Introduction

Overview

The Job Queue handles the executing of automated tasks within Sugar.

Components

The Job Queue consists of the followng 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 occuring job.
  • SugarCronJobs - The cron process that uses SugarJobQueue to run jobs. It is run periodically and does not support parallel execution.
Job_queue_actors.png

Stages

Schedule Stage

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

Execution Stage

The SQL queue table is checked for any jobs in pending status, if such jobs exist their status is set to running, and then the job is executed in accordance to its target and settings.

Cleanup Stage

The queue is checked for jobs that are in running state longer than the defined timeout. Such jobs are failed (they may be requeued if their definition includes requeing on failure).