Skip to content
Corridor V1.26.08 is out, see what's new

Technology

Run Scheduled Jobs

Ask AI

How Corridor's built-in scheduler works, how to configure its check interval, and how to trigger scheduled jobs manually or with an external scheduler.

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:

Terminal window
$ 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.

The scheduler can be configured to check for scheduled jobs at any interval of time. We would need to do the appropriate configurations in the 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', '*', '*', '*', '*')

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.

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

Terminal window
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.