Documentation ¶
Overview ¶
Package runner implements running a job.
Index ¶
Constants ¶
const ( // Number of times to attempt sending a job log to the RM. JOB_LOG_TRIES = 5 // Time to wait between attempts to send a job log to RM. JOB_LOG_RETRY_WAIT = 500 * time.Millisecond )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Factory ¶
type Factory interface {
Make(job proto.Job, requestId string, prevTries, totalTries uint) (Runner, error)
}
A Factory makes a Runner for one job. There are two try counts: prevTries and totalTries. prevTries is a gauge from [0, 1+retry], where retry is the retry count from the request spec. The prevTries count is per-sequence try, which is why it can reset to zero on sequence retry (handled by a chain.Reaper). On suspend/resume, jobs are stopped and the try on which it's stopped doesn't count, so prevTries is decremented by 1 on resume to retry. The totalTries count is a monotonically increasing global counter of how many times the job was run. This count is used for the proto.JobLog.Try field which cannot repeat a number because the job_log table primary key is <request_id, job_id, try>.
type Repo ¶
type Repo interface { Set(jobId string, runner Runner) Get(jobId string) Runner Remove(jobId string) Items() map[string]Runner Count() int }
Repo is a small wrapper around a concurrent map that provides the ability to store and retrieve Runners in a thread-safe way.
type Runner ¶
type Runner interface { // Run runs the job, blocking until it has completed or when Stop is called. // If the job fails, Run will retry it as many times as the job is configured // to be retried. After each run attempt, a Job Log is created and sent to // the RM. When the job successfully completes, or reaches the maximum number // of retry attempts, Run returns the final state of the job. Run(jobData map[string]interface{}) Return // Stop stops the job if it's running. The job is responsible for stopping // quickly because Stop blocks while waiting for the job to stop. Stop() error // Status returns the job try count and real-time status. The runner handles // the try count. The underlying job.Job must handle async, real-time status // requests while running. Status() Status }
A Runner runs and manages one job in a job chain. The job must implement the job.Job interface.