Documentation
¶
Index ¶
- type BaseModel
- type DBGetFilter
- type JobFilter
- type JobModel
- func (j *JobModel) BulkToPayload(jm []*JobModel) (p []*payload.JobResponse, err error)
- func (j *JobModel) Count(filter *JobFilter) (int, error)
- func (j *JobModel) Delete()
- func (j *JobModel) Get(filter *JobFilter) ([]*JobModel, error)
- func (j *JobModel) MarkJobFinished() error
- func (j *JobModel) Save() error
- func (j *JobModel) ToPayload() (*payload.JobResponse, error)
- func (j *JobModel) Update() error
- func (j *JobModel) WaitJob(ctx context.Context, cancel context.CancelFunc, filter *JobFilter) (*JobModel, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DBGetFilter ¶
type DBGetFilter struct {
// ID specifies a unique job identifier to filter by.
// If provided, the query typically returns a single match.
ID string
// Keyword specifies a search term for partial matching.
// This is usually applied against the job name or ID (e.g., "backup" matches "db-backup-01").
Keyword string
// Limit restricts the maximum number of records returned by the query.
// A value of 0 typically implies no limit or uses the system default.
Limit int
// SortDesc determines the sorting order of the results based on the timestamp.
// If true, results are ordered descending (newest first). If false, they are ordered ascending (oldest first).
SortDesc bool
// Offset specifies the number of records to skip before starting to return results.
// Used in conjunction with Limit for pagination.
Offset int
}
DBGetFilter defines the criteria used to query and filter job records from the database. It is typically passed to repository functions to refine the result set.
type JobFilter ¶
type JobFilter struct {
// ActiveOnly filters results to include only active jobs.
// Cannot be combined with FinishOnly.
ActiveOnly bool
// FinishOnly filters results to include only finished jobs whether job is success or failed.
// Cannot be combined with ActiveOnly.
FinishOnly bool
// MetadataFilter allows filtering jobs based on their metadata.
// Keys are metadata field names, and values are the desired values.
MetadataFilter map[string]string
// GeneralKeywordSearch applies to JobFilter.ID OR JobFilter.Keyword
GeneralKeywordSearch string
// HideCommand prevents the command from being exposed in the job response.
HideCommand bool `json:"hide_command,omitempty"`
DBGetFilter
}
type JobModel ¶
type JobModel struct {
ID string `db:"id"`
JobName string `db:"job_name"`
Command string `db:"command"` // JSON string representation of []string
Status int `db:"status"` // Integer cast from JobStatusEnum
ExitCode int `db:"exit_code"`
Metadata string `db:"metadata"` // JSON string representation of PayloadRegularMetadata
PID int `db:"pid"`
CreatedAt time.Time `db:"created_at"` // Generated automatically (current_timestamp)
UpdatedAt time.Time `db:"updated_at"` // Generated automatically (TRIGGER jobs_update_updated_at)
BaseModel
}
JobModel represents a single row in the 'jobs' database table. Complex fields (such as slices or maps) are serialized and stored as JSON strings.
func NewJobModel ¶
NewJobModel creates a database-ready JobModel from a JobResponse object. It serializes complex fields into JSON strings to prepare for database insertion.
func (*JobModel) BulkToPayload ¶
func (j *JobModel) BulkToPayload(jm []*JobModel) (p []*payload.JobResponse, err error)
BulkToPayload converts the bulk of raw database model back into a bulk of JobResponse struct.
func (*JobModel) Count ¶
Get fetch the job data from the table and return it as a int of JobModel size.
func (*JobModel) MarkJobFinished ¶
MarkFinished updates only the status and exit code of a job.
To use this function, the required property is `JobModel.ID` and `JobModel.ExitCode`.
func (*JobModel) ToPayload ¶
func (j *JobModel) ToPayload() (*payload.JobResponse, error)
ToPayload converts the raw database model back into a JobResponse struct. It handles the deserialization of JSON fields to ensure the data is ready for the CLI.