Scheduled Operations

This tutorial provides information on scheduled operations in the Order Management System (OMS). The OMS uses Celery to schedule tasks for operations such as pulling orders from Omnitron, creating packages, and updating shipment statuses. This guide explains how to manage the scheduling of these tasks through environment configurations and how to adjust task timings using either the schedule or crontab approach.

How Scheduling Works in OMS?​

OMS uses Celery to perform tasks that are scheduled at specific intervals. These tasks can be configured in the Environment (ENV) file, which contains the settings that control task behavior. After making changes to the ENV file, the server must be restarted for the changes to take effect.

Each task is defined by the following key parameters:

  • env_key: Enables or disables a task (default: true).

  • crontab_env_key: Specifies the crontab syntax for setting specific task timings.

  • schedule_env_key: Specifies the time interval between task runs.

  • schedule: Defines the interval in seconds for tasks using the schedule approach.

  • crontab: Uses crontab syntax to specify when the task should run.

1. env_key

The env_key is used to enable or disable a task. Each task has a unique env_key, and by default, this is set to true, meaning the task is enabled. To disable a task, simply set the env_key value to false.

2. crontab_env_key and crontab

This key is used when you want to run a task at a specific time. A crontab consists of five components: minute, hour, day of the month, month, and day of the week. To schedule a task using this approach, you need to add crontab_env_key and crontab values in your configuration file.

3. schedule_env_key and schedule

This is used when you want the task to run repeatedly at specific time intervals. Add schedule_env_key and schedule values in the configuration file for this approach.

Difference Between Crontab and Schedule Approaches

  • Crontab is ideal for running tasks at specific times (e.g., every day at 3 AM).

  • Schedule is better for tasks that should recur at regular intervals (e.g., every hour).

Tasks

1. GET ORDERS FROM OMNITRON​

This task pulls orders from Omnitron.

The default configuration is:

'get-omnitron-orders-cron': {
   'env_key': 'OMNITRON_ORDERS',
   'crontab_env_key': 'OMNITRON_ORDERS_CRONTAB',
   'schedule_env_key': 'OMNITRON_ORDERS_SCHEDULE',
   'task': 'oms.orders.tasks.get_orders_from_omnitron',
   'schedule': 60
}

In this example, the task runs every minute. To change this from the ENV file:

Schedule: Run every 5 minutes:

OMNITRON_ORDERS_SCHEDULE=60*5

Crontab: Run daily at 3:00 AM:

OMNITRON_ORDERS_CRONTAB=0,3,*,*,*

Disable the task:

OMNITRON_ORDERS=false

2. FULFILL WAITING ORDERS​

This task plans the orders pulled from Omnitron by starting the fulfillment process for unplanned orders, creating packages based on stock and scenario rules.

The default configuration is:

'fulfil-waiting-orders': {
   'env_key': 'FULFIL_WAITING_ORDERS',
   'crontab_env_key': 'FULFIL_WAITING_ORDERS_CRONTAB',
   'schedule_env_key': 'FULFIL_WAITING_ORDERS_SCHEDULE',
   'task': 'oms.fulfilment.tasks.fulfil_waiting_orders',
   'schedule': 60
}

In this example, the task runs every minute. To change this from the ENV file:

Schedule: Run every 5 minutes:

FULFIL_WAITING_ORDERS_SCHEDULE=60*5

Crontab: Run daily at 3:00 AM:

FULFIL_WAITING_ORDERS_CRONTAB=0,3,*,*,*

Disable the task:

FULFIL_WAITING_ORDERS=false

3. FULFILL RE-PLANNING ORDERS​

This task replans packages in the following states:

  • needs_replan

  • out_of_stock

  • defective_product

  • unavailable

It restarts the fulfillment process for packages marked with any of these states.

The default configuration is:

'fulfil-replanning-orders': {
   'env_key': 'FULFIL_REPLANNING_ORDERS',
   'crontab_env_key': 'FULFIL_REPLANNING_ORDERS_CRONTAB',
   'schedule_env_key': 'FULFIL_REPLANNING_ORDERS_SCHEDULE',
   'task': 'oms.fulfilment.tasks.fulfil_replaning_orders',
   'schedule': 60 * 60
}

In this example, the task runs every hour. To change this from the ENV file:

Schedule: Run every 5 hours:

FULFIL_REPLANNING_ORDERS_SCHEDULE=60*60*5

Crontab: Run daily at 3:00 AM:

FULFIL_REPLANNING_ORDERS_CRONTAB=0,3,*,*,*

Disable the task:

FULFIL_REPLANNING_ORDERS=false

4. RENEW OUT-OF-STOCK PACKAGES​

This task replans packages in the following states:

  • out_of_stock

  • defective_product

It restarts the fulfillment process for packages marked with any of these states.

The default configuration is:

'renew-out-of-stock-packages-cron': {
   'env_key': 'RENEW_OUT_OF_STOCK_PACKAGES',
   'crontab_env_key': 'RENEW_OUT_OF_STOCK_PACKAGES_CRONTAB',
   'schedule_env_key': 'RENEW_OUT_OF_STOCK_PACKAGES_SCHEDULE',
   'task': 'oms.fulfilment.tasks.retry_out_of_stock_packages',
   'schedule': 3 * 60 * 60
}

In this example, the task runs every 3 hours. To change this from the ENV file:

Schedule: Run every 5 hours:

RENEW_OUT_OF_STOCK_PACKAGES_SCHEDULE=60*60*5

Crontab: Run daily at 3:00 AM:

RENEW_OUT_OF_STOCK_PACKAGES_CRONTAB=0,3,*,*,*

Disable the task:

RENEW_OUT_OF_STOCK_PACKAGES=false

5. RENEW OUT-OF-STOCK TRANSFER ORDERS​

This task replans transfer orders in the following state:

  • out_of_stock

It restarts the fulfillment process for packages marked with this state.

The default configuration is:

'renew-out-of-stock-transfers-cron': {
   'env_key': 'RENEW_OUT_OF_STOCK_TRANSFERS',
   'crontab_env_key': 'RENEW_OUT_OF_STOCK_TRANSFERS_CRONTAB',
   'schedule_env_key': 'RENEW_OUT_OF_STOCK_TRANSFERS_SCHEDULE',
   'task': 'oms.fulfilment.tasks.retry_out_of_stock_transfers',
   'schedule': 3 * 60 * 60
}

In this example, the task runs every 3 hours. To change this from the ENV file:

Schedule: Run every 5 hours:

RENEW_OUT_OF_STOCK_TRANSFERS_SCHEDULE=60*60*5

Crontab: Run daily at 3:00 AM:

RENEW_OUT_OF_STOCK_TRANSFERS_CRONTAB=0,3,*,*,*

Disable the task:

RENEW_OUT_OF_STOCK_TRANSFERS=false

6. DAILY CLEAR INVENTORY DISCREPANCIES​

A package item can be marked as out-of-stock in the OMS. In such cases, a reservation record may be added for the product at the package's location, with the reservation type set as "inventory discrepancy". This prevents another package containing the same product from being created at that location.

This task clears inventory discrepancy reservations that prevent duplicate package creation.

The default configuration is:

'daily-clear-inventory-discrepancies': {
   'env_key': 'DAILY_CLEAR_INVENTORY_DISCREPANCIES',
   'crontab_env_key': 'DAILY_CLEAR_INVENTORY_DISCREPANCIES_CRONTAB',
   'schedule_env_key': 'DAILY_CLEAR_INVENTORY_DISCREPANCIES_SCHEDULE',
   'task': 'oms.reservations.tasks.clear_inventory_discrepancies',
   'crontab': '*/60,*,*,*,*'
}

In this example, the task runs every 60 minutes (1 hour). To change this from the ENV file:

Schedule: Run every 2 hours:

DAILY_CLEAR_INVENTORY_DISCREPANCIES_SCHEDULE=60*60*2

Crontab: Run daily at 3:15 AM:

DAILY_CLEAR_INVENTORY_DISCREPANCIES_CRONTAB=15,3,*,*,*

Disable the task:

DAILY_CLEAR_INVENTORY_DISCREPANCIES=false

7. UPDATE TRACKING INFORMATIONS​

This task is used to check cargo status of the packages.

The default configuration is:

'update-tracking-informations': {
   'env_key': 'UPDATE_TRACKING_INFORMATIONS',
   'crontab_env_key': 'UPDATE_TRACKING_INFORMATIONS_CRONTAB',
   'schedule_env_key': 'UPDATE_TRACKING_INFORMATIONS_SCHEDULE',
   'task': 'oms.shipments.tasks.update_all_tracking_information',
   'crontab': '0,2,*,*,*'
}

In this example, the task runs every day at 02:00 AM. To change this from the ENV file:

Schedule: Run every 4 hours:

UPDATE_TRACKING_INFORMATIONS_SCHEDULE=60*60*4

Crontab: Run daily at 3:30 AM:

UPDATE_TRACKING_INFORMATIONS_CRONTAB=30,3,*,*,*

Disable the task:

UPDATE_TRACKING_INFORMATIONS=false

8. UPDATE TRACKING INFORMATIONS SEVEN DAYS​

This task is used to check cargo status of the packages for the last seven days.

The default configuration is:

'update-tracking-informations-seven-days': {
   'env_key': 'UPDATE_TRACKING_INFORMATIONS_SEVEN_DAYS',
   'crontab_env_key': 'UPDATE_TRACKING_INFORMATIONS_SEVEN_DAYS_CRONTAB',
   'schedule_env_key': 'UPDATE_TRACKING_INFORMATIONS_SEVEN_DAYS_SCHEDULE',
   'task': 'oms.shipments.tasks.update_all_seven_days_tracking_information',
   'schedule': 4 * 60 * 60
}

In this example, the task runs every 4 hours. To change this from the ENV file:

Schedule: Run every 3 hours:

UPDATE_TRACKING_INFORMATIONS_SEVEN_DAYS_SCHEDULE=60*60*3

Crontab: Run daily at 4:30 AM:

UPDATE_TRACKING_INFORMATIONS_SEVEN_DAYS_CRONTAB=30,4,*,*,*

Disable the task:

UPDATE_TRACKING_INFORMATIONS_SEVEN_DAYS=false

9. UPDATE TRANSFER SHIPMENTS TRACKING INFORMATIONS​

This task is used to check the cargo status of transfer orders.

The default configuration is:

'update-transfer-shipments-tracking-informations': {
   'env_key': 'UPDATE_TRANSFER_SHIPMENTS_TRACKING_INFORMATIONS',
   'crontab_env_key': 'UPDATE_TRANSFER_SHIPMENTS_TRACKING_INFORMATIONS_CRONTAB',
   'schedule_env_key': 'UPDATE_TRANSFER_SHIPMENTS_TRACKING_INFORMATIONS_SCHEDULE',
   'task': 'oms.shipments.tasks.update_all_transfer_order_tracking_information',
   'schedule': 4 * 60 * 60
}

In this example, the task runs every 4 hours. To change this from the ENV file:

Schedule: Run every 3 hours:

UPDATE_TRANSFER_SHIPMENTS_TRACKING_INFORMATIONS_SCHEDULE=60*60*3

Crontab: Run daily at 4:30 AM:

UPDATE_TRANSFER_SHIPMENTS_TRACKING_INFORMATIONS_CRONTAB=30,4,*,*,*

Disable the task:

UPDATE_TRANSFER_SHIPMENTS_TRACKING_INFORMATIONS=false

10. UNDELIVERED WHISPERER TASKS​

This task is used to resend undelivered webhooks.

The default configuration is:

'undelivered-whisperer-tasks': {
   'env_key': 'UNDELIVERED_WHISPERER_TASKS',
   'crontab_env_key': 'UNDELIVERED_WHISPERER_TASKS_CRONTAB',
   'schedule_env_key': 'UNDELIVERED_WHISPERER_TASKS_SCHEDULE',
   'task': 'whisperer.tasks.undelivered_event_scanner',
   'crontab': '*/15,*,*,*,*'
}

In this example, the task runs every 15 minutes, such as at 20:45, 21:00, 21:15, 21:30, and 21:45…

To change this from the ENV file:

Schedule: Run every 30 minutes:

UNDELIVERED_WHISPERER_TASKS_SCHEDULE=60*30

Crontab: Run every 30th minutes, such as at 20:30, 21:00, and 21:30:

UNDELIVERED_WHISPERER_TASKS_CRONTAB=*/30,*,*,*,*

Disable the task:

UNDELIVERED_WHISPERER_TASKS=false

11. DB MAINTENANCE​

This task performs maintenance on specific database tables (VACUUM and ANALYZE).

The default configuration is:

'db-maintenance': {
   'env_key': 'DB_MAINTENANCE',
   'crontab_env_key': 'DB_MAINTENANCE_CRONTAB',
   'schedule_env_key': 'DB_MAINTENANCE_SCHEDULE',
   'task': 'oms.base.tasks.db_maintenance',
   'crontab': '0,0,*,*,*'
}

In this example, the task runs every day at midnight (00:00 AM)

To change this from the ENV file:

Schedule: Run every day:

DB_MAINTENANCE_SCHEDULE=60*60*24

Crontab: Run daily at 03:00 AM:

DB_MAINTENANCE_CRONTAB=0,3,*,*,*

Disable the task:

DB_MAINTENANCE=false

12. ARCHIVE OLD AUDIT EVENTS​

This task archives audit event logs older than 120 days.

The default configuration is:

"archive-old-audit-events": {
   'env_key': 'ARCHIVE_OLD_AUDIT_EVENTS',
   'crontab_env_key': 'ARCHIVE_OLD_AUDIT_EVENTS_CRONTAB',
   'schedule_env_key': 'ARCHIVE_OLD_AUDIT_EVENTS_SCHEDULE',
   'task': "django_audit_events.tasks.archive_old_audit_events",
   'crontab': '30,12,*,*,*',
   'args': (),
   'kwargs': {"older_than": 120}
}

In this example, the task runs daily at 00:30 PM. To change this from the ENV file:

Schedule: Run every 12 hours:

ARCHIVE_OLD_AUDIT_EVENTS_SCHEDULE=60*60*12

Crontab: Run daily at midnight:

ARCHIVE_OLD_AUDIT_EVENTS_CRONTAB=0,0,*,*,*

Disable the task:

ARCHIVE_OLD_AUDIT_EVENTS=false

13. PROCESS CANCELLATION PLANS​

This task processes cancellation plans pulled from Omnitron.

The default configuration is:

"process-cancellation-plans": {
   'env_key': 'PROCESS_CANCELLATION_PLANS',
   'crontab_env_key': 'PROCESS_CANCELLATION_PLANS_CRONTAB',
   'schedule_env_key': 'PROCESS_CANCELLATION_PLANS_SCHEDULE',
   'task': "oms.orders.tasks.process_cancellation_plans",
   'schedule': 60 * 60
}

In this example, the task runs every hour.

To change this from the ENV file:

Schedule: Run every 2 hours:

PROCESS_CANCELLATION_PLANS_SCHEDULE=60*60*2

Crontab: Run daily at 03:00 PM:

PROCESS_CANCELLATION_PLANS_CRONTAB=0,15,*,*,*

Disable the task:

PROCESS_CANCELLATION_PLANS=false

14. RERUN PLANS FOR CANCELLATION WAITING PACKAGES​

This task restarts the cancellation process for packages in the cancellation_waiting state depending on the situation.

The default configuration is:

"rerun-plans-for-cancellation-waiting-packages": {
   'env_key': 'RERUN_PLANS_FOR_CANCELLATION_WAITING_PACKAGES',
   'crontab_env_key': 'RERUN_PLANS_FOR_CANCELLATION_WAITING_PACKAGES_CRONTAB',
   'schedule_env_key': 'RERUN_PLANS_FOR_CANCELLATION_WAITING_PACKAGES_SCHEDULE',
   'task': "oms.orders.tasks.rerun_plans_for_cancellation_waiting_packages",
   'schedule': 60 * 60
}

In this example, the task runs every hour.

To change this from the ENV file:

Schedule: Run every 2 hours:

RERUN_PLANS_FOR_CANCELLATION_WAITING_PACKAGES_SCHEDULE=60*60*2

Crontab: Run daily at 03:00 PM:

RERUN_PLANS_FOR_CANCELLATION_WAITING_PACKAGES_CRONTAB=0,15,*,*,*

Disable the task:

RERUN_PLANS_FOR_CANCELLATION_WAITING_PACKAGES=false

15. UPDATE ORDER EXECUTION PLAN CONTEXT​

This task updates the context of OrderExecutionPlan for packages with a state ≥ 450 and plans created within the last 3 months.

The default configuration is:

"update-order-execution-plan-context": {
   'env_key': 'UPDATE_ORDER_EXECUTION_PLAN_CONTEXT',
   'crontab_env_key': 'UPDATE_ORDER_EXECUTION_PLAN_CONTEXT_CRONTAB',
   'schedule_env_key': 'UPDATE_ORDER_EXECUTION_PLAN_CONTEXT_SCHEDULE',
   'task': "oms.fulfilment.tasks.update_order_execution_plan_context",
   'crontab': '0,0,*,*,*' 
}

In this example, the task runs daily at midnight (00:00 AM).

To change this from the ENV file:

Schedule: Run every two hours:

UPDATE_ORDER_EXECUTION_PLAN_CONTEXT_SCHEDULE=60*60

Crontab: Run daily at 03:00 AM:

UPDATE_ORDER_EXECUTION_PLAN_CONTEXT_CRONTAB=0,3,*,*,*

Disable the task:

UPDATE_ORDER_EXECUTION_PLAN_CONTEXT=false

16. WHISPERER TRIGGER EVENT QUEUE EVENTS​

This task processes delayed events in the EventQueue model, delivering the relevant events. Its purpose is to handle EventQueue records that were modified a specific time ago (before a configurable delay) and trigger the events linked to those records.

The default configuration is:

'whisperer_trigger_event_queue_events': {
   'env_key': 'WHISPERER_TRIGGER_EVENT_QUEUE_EVENTS',
   'crontab_env_key': 'WHISPERER_TRIGGER_EVENT_QUEUE_EVENTS_CRONTAB',
   'schedule_env_key': 'WHISPERER_TRIGGER_EVENT_QUEUE_EVENTS_SCHEDULE',
   'task': 'whisperer.tasks.trigger_event_queue_events',
   'schedule': 60 * 15,
}

In this example, the task runs every 15 minutes.

To change this from the ENV file:

Schedule: Run every 30 minutes:

WHISPERER_TRIGGER_EVENT_QUEUE_EVENTS_SCHEDULE=60*30

Crontab: Run at the 30th minute of each hour (e.g., 20:00, 20:30, 21:00):

WHISPERER_TRIGGER_EVENT_QUEUE_EVENTS_CRONTAB=*/30,*,*,*,*

Disable the task:

WHISPERER_TRIGGER_EVENT_QUEUE_EVENTS=false

17. DELETE OLD WEBHOOK REQUEST RECORDS​

This task deletes old webhook request records.

The default configuration is:

'delete_old_webhook_request_records': {
   'env_key': 'DELETE_OLD_WEBHOOK_REQUEST_RECORDS',
   'crontab_env_key': 'DELETE_OLD_WEBHOOK_REQUEST_RECORDS_CRONTAB',
   'schedule_env_key': 'DELETE_OLD_WEBHOOK_REQUEST_RECORDS_SCHEDULE',
   'task': 'oms.integrations.tasks.delete_old_webhook_request_records',
   'schedule': 60 * 2,
}

In this example, the task runs every 2 minutes.

To change this from the ENV file:

Schedule: Run every 10 minutes:

DELETE_OLD_WEBHOOK_REQUEST_RECORDS_SCHEDULE=60*10

Crontab: Run at the 15th minute of each hour (e.g., 20:00, 20:15, 20:30):

DELETE_OLD_WEBHOOK_REQUEST_RECORDS_CRONTAB=*/15,*,*,*,*

Disable the task:

DELETE_OLD_WEBHOOK_REQUEST_RECORDS=false

18. AUTO RUN SHIP-THE-PACKAGE COMMAND​

This task automatically runs the SHIP_THE_PACKAGE command for packages in the packed state. It checks packages with a shipment record, verifies the shipment status, and runs the command accordingly, updating the package's status.

The default configuration is:

'auto_run_ship_the_package_command': {
   'env_key': 'AUTO_RUN_SHIP_THE_PACKAGE_COMMAND',
   'crontab_env_key': 'AUTO_RUN_SHIP_THE_PACKAGE_COMMAND_CRONTAB',
   'schedule_env_key': 'AUTO_RUN_SHIP_THE_PACKAGE_COMMAND_SCHEDULE',
   'task': 'oms.shipments.tasks.auto_run_ship_the_package_command',
   'schedule': 2 * 60 * 60,
}

In this example, the task runs every 2 hours.

To change this from the ENV file:

Schedule: Run every 4 hours:

AUTO_RUN_SHIP_THE_PACKAGE_COMMAND_SCHEDULE=60*60*4

Crontab: Run daily at 03:00 AM:

AUTO_RUN_SHIP_THE_PACKAGE_COMMAND_CRONTAB=0,3,*,*,*

Disable the task:

AUTO_RUN_SHIP_THE_PACKAGE_COMMAND=false

Last updated

Was this helpful?