daemon

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 19, 2025 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindJobDataFilename

func FindJobDataFilename(c config.BobbitConfig, s payload.JobSearchMetadata) (p payload.JobDetailMetadata, err error)

FindJobDataFilename searches for a job data filename based on the provided configuration and search metadata. It returns the found JobDetailMetadata and an error if an issue occurs during directory reading or parsing.

func GenerateJobDataFilename

func GenerateJobDataFilename(c config.BobbitConfig, p payload.JobDetailMetadata, extFile DaemonFileTypeEnum) string

GenerateJobDataFilename generates a filename for job-related data based on the provided configuration, job metadata, and file type.

func ParseExitCode

func ParseExitCode(c config.BobbitConfig, job *payload.JobResponse) error

ParseExitCode reads the exit code for a job from a file and updates the job's status accordingly. It returns an error if reading or parsing the exit code fails.

func ParseJobDataFilename

func ParseJobDataFilename(filename string) (p payload.JobDetailMetadata, err error)

ParseJobDataFilename parses the job detail metadata from a given filename. It returns a JobDetailMetadata struct and an error if parsing fails.

func SplitFilenameFromExtfile

func SplitFilenameFromExtfile(filename string) string

SplitFilenameFromExtfile splits the filename from its extension. It returns the filename without the extension.

Types

type DaemonError

type DaemonError struct {
	Message     string
	ParentError error
}

func (*DaemonError) Error

func (d *DaemonError) Error() string

type DaemonFileTypeEnum

type DaemonFileTypeEnum string

DaemonFileTypeEnum represents the type of data file associated with a daemon job.

const (
	// DAEMON_LOCKFILE indicates a lock file, signifying a job is running.
	DAEMON_LOCKFILE DaemonFileTypeEnum = "lockfile"
	// DAEMON_LOGFILE indicates a log file for job output.
	DAEMON_LOGFILE DaemonFileTypeEnum = "log"
	// DAEMON_METADATA indicates a metadata file containing job details.
	DAEMON_METADATA DaemonFileTypeEnum = "metadata"
	// DAEMON_EXITCODE indicates a file containing the job's exit code.
	DAEMON_EXITCODE DaemonFileTypeEnum = "exitcode"
)

type DaemonPayloadError

type DaemonPayloadError struct {
	Message     string
	JobID       string
	ParentError error
}

func (*DaemonPayloadError) Error

func (d *DaemonPayloadError) Error() string

func (*DaemonPayloadError) Warning

func (d *DaemonPayloadError) Warning()

type DaemonStruct

type DaemonStruct struct {
	SocketListener net.Listener
	config.BobbitConfig
}

DaemonStruct holds the main components of the Bobbit daemon, including its socket listener and configuration.

func CreateDaemon

func CreateDaemon(c config.BobbitConfig) (*DaemonStruct, error)

CreateDaemon initializes and starts the daemon. It checks for existing daemon instances, creates necessary data directories, and sets up the Unix socket listener. It returns a pointer to a DaemonStruct or an error if initialization fails.

func (*DaemonStruct) CleanupDaemon

func (d *DaemonStruct) CleanupDaemon(sigChan <-chan os.Signal)

CleanupDaemon listens for an OS signal and performs cleanup operations before exiting. It removes the daemon's socket file.

func (*DaemonStruct) HandleJob

func (d *DaemonStruct) HandleJob(jc *JobContext) error

HandleJob processes a new job request. It validates the job payload, generates a unique ID if not provided, creates necessary data files (lock, log, metadata), executes the command, captures its output and exit code, and cleans up the lock file.

func (*DaemonStruct) HandleVibeCheck

func (d *DaemonStruct) HandleVibeCheck(jc *JobContext) error

HandleVibeCheck handles a "vibe check" request, which typically serves as a basic ping to confirm the daemon is responsive. It unmarshals the request metadata.

func (*DaemonStruct) ListJob

func (d *DaemonStruct) ListJob(jc *JobContext) error

ListJob handles requests to list jobs. It reads job data from the configured directory, filters them based on `JobSearchMetadata` criteria (e.g., active only, limit), parses their status and optional metadata, sorts them, and sends the results back to the client.

Check payload.JobSearchMetadata for more information.

func (*DaemonStruct) NewJobContext

func (d *DaemonStruct) NewJobContext(conn net.Conn) *JobContext

NewJobContext creates and returns a new JobContext for a given network connection. This context is used to manage a single job request.

func (*DaemonStruct) StatusJob

func (d *DaemonStruct) StatusJob(jc *JobContext) error

StatusJob handles requests to retrieve the current status of a specific job. It finds the job based on the provided search metadata, parses its exit code to determine its status, and sends the `JobResponse` back to the client.

func (*DaemonStruct) StopJob added in v0.3.0

func (d *DaemonStruct) StopJob(jc *JobContext) error

StopJob handles requests to stop the specific job. If the job exist, the return is JobResponse. If the job not exist, the return is an empty JobResponse.

func (*DaemonStruct) WaitJob

func (d *DaemonStruct) WaitJob(jc *JobContext) error

WaitJob handles requests to wait for a specific job to complete. It continuously checks for the absence of the job's lock file and responds to the client with the job's final status once completed. It also handles client connection timeouts.

type JobContext

type JobContext struct {
	Payload payload.JobPayload
	// contains filtered or unexported fields
}

JobContext holds the context for a single job request handled by the daemon, including the network connection and the job payload.

func (*JobContext) Close

func (jc *JobContext) Close()

Close closes the network connection associated with the JobContext.

func (*JobContext) GetPayload

func (jc *JobContext) GetPayload() error

GetPayload reads and decodes a JobPayload from the JobContext's network connection. It populates the Payload field of the JobContext and returns an error if decoding fails. If the payload's timestamp is zero, it defaults to the current time.

func (*JobContext) SendPayload

func (jc *JobContext) SendPayload(target any) error

SendPayload encodes and sends the given target object over the JobContext's network connection. It returns an error if encoding or writing fails.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL