Skip to content

Run Scheduled Jobs

Corridor provides an in-built scheduler to schedule and run jobs. The scheduler checks at regular intervals if any job has been scheduled by the user to run by that time and starts the execution.

The user has the ability to run any or all the scheduled jobs by using the run-scheduled-jobs utility by specifying the corresponding options.

The command with available option:

$ corridor-api scripts run-scheduled-jobs --help

Usage: corridor-api scripts run-scheduled-jobs [OPTIONS]

  Command to run scheduled jobs which need to be run before `execution-time`

Options:
  --job-id INTEGER       Job ids to check if needed to run
  --execution-time TEXT  Time by which the scheduled jobs are run
  --help                 Show this message and exit.

By default, the Corridor scheduler is enabled.

Scheduling configurations in Corridor

The scheduler can be configured to check for scheduled jobs at any interval of time. We would need to do the appropriate configurations in api_config.py file.

# Refer(for format): https://docs.celeryproject.org/en/v4.0.0/reference/celery.schedules.html#celery.schedules.crontab
from celery.schedules import crontab
CORRIDOR_CRON_SCHEDULE = crontab('*/30', '*', '*', '*', '*')

Using external schedulers

The user has the option to use external schedulers to run scheduled jobs, based on the requirements. The external scheduler could be a simple cron job.

Example

To run all jobs scheduled to run by 2020-01-01 midnight:

corridor-api scripts run-scheduled-jobs --execution-time 2020-01-01:00:00:00

There would not be any output generated from the command, but the scheduled jobs will start getting executed.