Let the platform do the work

Job Queue

Overview

The Job Queue executes automated tasks in Sugar through a scheduler, which integrates with external UNIX systems and Windows systems to run jobs that are scheduled through those systems. Jobs are the individual runs of the specified function from a scheduler. 

The Job Queue is composed of the following parts:

  • SugarJobQueue : Implements the queue functionality. The queue contains the various jobs.
  • SchedulersJob : A single instance of a job. This represents a single executable task and is held in the SugarJobQueue.
  • Scheduler : This is a periodically occurring job.
  • SugarCronJobs : The cron process that uses SugarJobQueue to run jobs. It runs periodically and does not support parallel execution.

rest/v11/doc_PagesFiles/eea2f496-0878-5047-88c3-550287cebffe/file/uploadfile?force_download=0&platform=base

Stages

Schedule Stage

On the scheduling stage (checkPendingJobs in Scheduler class), the queue checks if any schedules are qualified to run at this time and do not have job instance already in the queue. If such schedules exist, a job instance will immediately be created for each.

Execution Stage

The SQL queue table is checked for any jobs in the "Pending" status. These will be set to "Running"' and then executed in accordance to its target and settings.

Cleanup Stage

The queue is checked for jobs that are in the "Running" state longer than the defined timeout. Such jobs are considered "Failed" jobs (they may be re-queued if their definition includes re-queuing on failure).