Documentation ¶
Index ¶
Constants ¶
const ( // KindGeneric : Kind of generic job KindGeneric = "Generic" // KindScheduled : Kind of scheduled job KindScheduled = "Scheduled" // KindPeriodic : Kind of periodic job KindPeriodic = "Periodic" )
const ( // SampleJob is name of demo job SampleJob = "DEMO" // ImageScanJob is name of scan job it will be used as key to register to job service. ImageScanJob = "IMAGE_SCAN" // ImageScanAllJob is the name of "scanall" job in job service ImageScanAllJob = "IMAGE_SCAN_ALL" // ImageGC the name of image garbage collection job in job service ImageGC = "IMAGE_GC" // Replication : the name of the replication job in job service Replication = "REPLICATION" // ReplicationScheduler : the name of the replication scheduler job in job service ReplicationScheduler = "IMAGE_REPLICATE" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ActionRequest ¶ added in v1.8.0
type ActionRequest struct {
Action string `json:"action"`
}
ActionRequest defines for triggering job action like stop/cancel.
type Context ¶ added in v1.8.0
type Context interface { // Build the context based on the parent context // // A new job context will be generated based on the current context // for the provided job. // // Returns: // new Context based on the parent one // error if meet any problems Build(tracker Tracker) (Context, error) // Get property from the context // // prop string : key of the context property // // Returns: // The data of the specified context property if have // bool to indicate if the property existing Get(prop string) (interface{}, bool) // SystemContext returns the system context // // Returns: // context.Context SystemContext() context.Context // Checkin is bridge func for reporting detailed status // // status string : detailed status // // Returns: // error if meet any problems Checkin(status string) error // OPCommand return the control operational command like stop if have // // Returns: // op command if have // flag to indicate if have command OPCommand() (OPCommand, bool) // Return the logger GetLogger() logger.Interface // Get tracker Tracker() Tracker }
Context is combination of BaseContext and other job specified resources. Context will be the real execution context for one job.
type ContextInitializer ¶ added in v1.8.0
ContextInitializer is a func to initialize the concrete job context
type HookCallback ¶ added in v1.8.0
type HookCallback func(hookURL string, change *StatusChange) error
HookCallback defines a callback to trigger when hook events happened
type Interface ¶ added in v1.5.0
type Interface interface { // Declare how many times the job can be retried if failed. // // Return: // uint: the failure count allowed. If it is set to 0, then default value 4 is used. MaxFails() uint // Tell the worker worker if retry the failed job when the fails is // still less that the number declared by the method 'MaxFails'. // // Returns: // true for retry and false for none-retry ShouldRetry() bool // Indicate whether the parameters of job are valid. // // Return: // error if parameters are not valid. NOTES: If no parameters needed, directly return nil. Validate(params Parameters) error // Run the business logic here. // The related arguments will be injected by the workerpool. // // ctx Context : Job execution context. // params map[string]interface{} : parameters with key-pair style for the job execution. // // Returns: // error if failed to run. NOTES: If job is stopped or cancelled, a specified error should be returned // Run(ctx Context, params Parameters) error }
Interface defines the related injection and run entry methods.
type Metadata ¶ added in v1.8.0
type Metadata struct { JobKind string `json:"kind"` ScheduleDelay uint64 `json:"schedule_delay,omitempty"` Cron string `json:"cron_spec,omitempty"` IsUnique bool `json:"unique"` }
Metadata stores the metadata of job.
type OPCommand ¶ added in v1.8.0
type OPCommand string
OPCommand is the type of job operation commands
type Parameters ¶ added in v1.8.0
type Parameters map[string]interface{}
Parameters for job execution.
type Request ¶ added in v1.8.0
type Request struct {
Job *RequestBody `json:"job"`
}
Request is the request of launching a job.
type RequestBody ¶ added in v1.8.0
type RequestBody struct { Name string `json:"name"` Parameters Parameters `json:"parameters"` Metadata *Metadata `json:"metadata"` StatusHook string `json:"status_hook"` }
RequestBody keeps the basic info.
type SimpleStatusChange ¶ added in v1.8.0
type SimpleStatusChange struct { JobID string `json:"job_id"` TargetStatus string `json:"target_status"` }
SimpleStatusChange only keeps job ID and the target status
type Stats ¶ added in v1.8.0
type Stats struct {
Info *StatsInfo `json:"job"`
}
Stats keeps the result of job launching.
type StatsInfo ¶ added in v1.8.0
type StatsInfo struct { JobID string `json:"id"` Status string `json:"status"` JobName string `json:"name"` JobKind string `json:"kind"` IsUnique bool `json:"unique"` RefLink string `json:"ref_link,omitempty"` CronSpec string `json:"cron_spec,omitempty"` EnqueueTime int64 `json:"enqueue_time"` UpdateTime int64 `json:"update_time"` RunAt int64 `json:"run_at,omitempty"` CheckIn string `json:"check_in,omitempty"` CheckInAt int64 `json:"check_in_at,omitempty"` DieAt int64 `json:"die_at,omitempty"` WebHookURL string `json:"web_hook_url,omitempty"` UpstreamJobID string `json:"upstream_job_id,omitempty"` // Ref the upstream job if existing NumericPID int64 `json:"numeric_policy_id,omitempty"` // The numeric policy ID of the periodic job Parameters Parameters `json:"parameters,omitempty"` }
StatsInfo keeps the stats of job
type Status ¶ added in v1.8.0
type Status string
Status of job
const ( // PendingStatus : job status pending PendingStatus Status = "Pending" // RunningStatus : job status running RunningStatus Status = "Running" // StoppedStatus : job status stopped StoppedStatus Status = "Stopped" // ErrorStatus : job status error ErrorStatus Status = "Error" // SuccessStatus : job status success SuccessStatus Status = "Success" // ScheduledStatus : job status scheduled ScheduledStatus Status = "Scheduled" )
func (Status) Compare ¶ added in v1.8.0
Compare the two job status if < 0, s before another status if == 0, same status if > 0, s after another status
type StatusChange ¶ added in v1.8.0
type StatusChange struct { JobID string `json:"job_id"` Status string `json:"status"` CheckIn string `json:"check_in,omitempty"` Metadata *StatsInfo `json:"metadata,omitempty"` }
StatusChange is designed for reporting the status change via hook.
type Tracker ¶ added in v1.8.0
type Tracker interface { // Save the job stats which tracked by this tracker to the backend // // Return: // none nil error returned if any issues happened Save() error // Load the job stats which tracked by this tracker with the backend data // // Return: // none nil error returned if any issues happened Load() error // Get the job stats which tracked by this tracker // // Returns: // *models.Info : job stats data Job() *Stats // Update the properties of the job stats // // fieldAndValues ...interface{} : One or more properties being updated // // Returns: // error if update failed Update(fieldAndValues ...interface{}) error // NumericID returns the numeric ID of periodic job. // Please pay attention, this only for periodic job. NumericID() (int64, error) // Mark the periodic job execution to done by update the score // of the relation between its periodic policy and execution to -1. PeriodicExecutionDone() error // Check in message CheckIn(message string) error // Update status with retry enabled UpdateStatusWithRetry(targetStatus Status) error // The current status of job Status() (Status, error) // Expire the job stats data Expire() error // Switch status to running Run() error // Switch status to stopped Stop() error // Switch the status to error Fail() error // Switch the status to success Succeed() error }
Tracker is designed to track the life cycle of the job described by the stats The status change is linear and then has strict preorder and successor Check should be enforced before switching
Pending is default status when creating job, so no need to switch
func NewBasicTrackerWithID ¶ added in v1.8.0
func NewBasicTrackerWithID( ctx context.Context, jobID string, ns string, pool *redis.Pool, callback HookCallback, ) Tracker
NewBasicTrackerWithID builds a tracker with the provided job ID
func NewBasicTrackerWithStats ¶ added in v1.8.0
func NewBasicTrackerWithStats( ctx context.Context, stats *Stats, ns string, pool *redis.Pool, callback HookCallback, ) Tracker
NewBasicTrackerWithStats builds a tracker with the provided job stats