Documentation
¶
Index ¶
- func FindJobDataFilename(c config.BobbitConfig, s payload.JobSearchMetadata) (p payload.JobDetailMetadata, err error)
- func GenerateJobDataFilename(c config.BobbitConfig, p payload.JobDetailMetadata, extFile DaemonFileTypeEnum) string
- func ParseExitCode(c config.BobbitConfig, job *payload.JobResponse) error
- func ParseJobDataFilename(filename string) (p payload.JobDetailMetadata, err error)
- func SplitFilenameFromExtfile(filename string) string
- type DaemonError
- type DaemonFileTypeEnum
- type DaemonPayloadError
- type DaemonStruct
- func (d *DaemonStruct) CleanupDaemon(sigChan <-chan os.Signal)
- func (d *DaemonStruct) HandleJob(jc *JobContext) error
- func (d *DaemonStruct) HandleVibeCheck(jc *JobContext) error
- func (d *DaemonStruct) ListJob(jc *JobContext) error
- func (d *DaemonStruct) NewJobContext(conn net.Conn) *JobContext
- func (d *DaemonStruct) StatusJob(jc *JobContext) error
- func (d *DaemonStruct) WaitJob(jc *JobContext) error
- type JobContext
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 ¶
SplitFilenameFromExtfile splits the filename from its extension. It returns the filename without the extension.
Types ¶
type DaemonError ¶
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 ¶
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.
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) 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.