Skip to main content

Cron Jobs & Scheduled Tasks

This document lists all console commands intended to run on a schedule, their purpose, and concurrency controls.

Note: The production crontab is configured server-side and is not committed to this repository. The schedules listed below are approximate based on code comments and known operational patterns.

Concurrency Guard: AlreadyRunningFilter

File: console/filters/AlreadyRunningFilter.php

Most scheduled commands use AlreadyRunningFilter to prevent concurrent execution:

  • Stores process state in SystemState table
  • 2-hour timeout before a stalled process is force-cleared
  • State tracked via SystemStateProcessesRepository (console/models/SystemStateProcessesRepository.php)
  • State key format: activeProcessRunning/<processName>

Used by 17+ console controllers.

Critical Scheduled Tasks

Order Processing

  • Command: php yii order/process [--orderId=ID] [--postToNav=0|1]
  • File: console/controllers/OrderController.php
  • Schedule: ~Every 2 minutes
  • Filter: AlreadyRunningFilter
  • Purpose: Processes pending orders — allocates stock, issues digital entitlements, posts to NAV
  • Additional action: order/process-pending-non-refundable-state — checks audio product refundability
  • Command: php yii sync/availabilitySync [--markPermanentlyOutOfStockProducts=1]
  • File: common/synchronizations/nav/sync/AvailabilitySync.php (via SyncController)
  • Schedule: ~Every 35 minutes, hours 9–22
  • Filter: AlreadyRunningFilter
  • Purpose: Pulls inventory from NAV ItemsAvailableForWeb table, updates product availability types, triggers back-in-stock notifications
  • Safety: Minimum threshold of 30k items — aborts if NAV returns fewer (indicates sync error)
  • Command: php yii sync/orderSync [--webStoreNavCode=WEB|WEB2]
  • File: common/synchronizations/nav/sync/OrderSync.php (via SyncController)
  • Schedule: ~Every 30 minutes
  • Filter: AlreadyRunningFilter
  • Purpose: Reconciles local orders with NAV posted documents and open orders

Elasticsearch Spool

  • Command: php yii elastic/spool
  • File: console/controllers/ElasticController.php
  • Schedule: Frequent (every few minutes)
  • Purpose: Processes queued search index updates
  • Details: See ../integrations/ELASTICSEARCH_SPOOL.md

Notification Tasks

Notification Generation & Sending

  • Command: php yii notification/generate --type=basket|order|offers [--dayOffset=N] [--webStoreNavCode=...]
  • Command: php yii notification/send [--webStoreNavCode=...]
  • Command: php yii notification/clear-expired
  • File: console/controllers/NotificationController.php
  • Filter: AlreadyRunningFilter
  • Purpose: Generates special offer, basket reminder, and order feedback notifications; sends queued notifications; clears expired ones (3 days for wishlist, 2 days for product ending)

Back-in-Stock Notifications

  • Command: php yii back-in-stock-notification/send-emails
  • Command: php yii back-in-stock-notification/cleanup-old-emails
  • File: console/controllers/BackInStockNotificationController.php
  • Filter: AlreadyRunningFilter
  • Purpose: Sends back-in-stock emails; deletes notifications older than 14 days

Cleanup & Maintenance Tasks

General Cleanup

  • Command: php yii cleanup/<action>
  • File: console/controllers/CleanupController.php
  • Purpose: See ./CLEANUP_JOBS.md for full details
ActionThresholdDescription
failed-orders8 hoursMarks processing orders as failed
failed-logins30 daysRemoves old failed login attempts
obsolete-products60 daysDeletes obsolete products
failed-async-processes8 hoursClears stale async flags
client-basket-sanitize24 hoursRemoves empty baskets
playback-breakpointsCleans orphaned audiobook playback data
flush-cacheFlushes entire cache

Queue Maintenance

  • Command: php yii queue-failed-jobs/run-all
  • Command: php yii queue-failed-jobs/flush
  • File: console/controllers/QueueFailedJobsController.php
  • Purpose: Re-queue or flush failed background jobs

Statistics & Analytics Tasks

  • Command: php yii ctr/sync-stat
  • Command: php yii ctr/clear-old-stat-data
  • File: console/controllers/CtrController.php
  • Filter: AlreadyRunningFilter
  • Purpose: Updates click-through rate statistics for banners; clears data older than 1 month

Product Badge Computation

  • Command: php yii product-badge/compute-product-badges
  • File: console/controllers/ProductBadgeController.php
  • Filter: AlreadyRunningFilter
  • Purpose: Recomputes product badges (bestseller, new, etc.)

Subscription Tasks

Subscription Billing

  • Command: php yii subscription/bill
  • Command: php yii subscription/update-statistics
  • File: console/controllers/SubscriptionController.php
  • Filter: None
  • Purpose: Bills upcoming payment subscriptions via EveryPay; updates subscription statistics for audio/ebook stores

Content Generation Tasks

Sitemap Generation

  • Command: php yii sitemap/index [--webStoreNavCode=...] (cron also scps the output to the FE web servers that serve it)
  • Schedule: 11 7 * * 0 (weekly, Sunday 07:11; was 11 7 * * 4,0 twice-weekly until 2026-06)
  • File: console/controllers/SitemapController.php
  • Filter: AlreadyRunningFilter
  • Purpose: Generates XML sitemaps for products, categories, authors, publishers, series, content pages. 8000 items per file.
  • Monitoring: Daily health report "Sitemap — generation freshness" section (per-entity counts, partial-failure + staleness detection, section errors). See ../reference/SITEMAP.md.

Feed Export

  • Command: php yii feed-exporter/generate-csv
  • Command: php yii feed-exporter/generate-facebook-csv
  • Command: php yii feed-exporter/generate-google-csv
  • Command: php yii feed-exporter/generate-google-watch-csv
  • Command: php yii feed-exporter/generate-products-csv
  • File: console/controllers/FeedExporterController.php
  • Filter: AlreadyRunningFilter
  • Purpose: Generates product feeds for external systems (resellers, Facebook Catalog, Google Shopping)

External Integration Syncs

All integration syncs are invoked via php yii sync/<handlerName> (dynamic actions from SyncHandlerFactory) or via dedicated controllers:

ControllerCommand PrefixIntegration
AnvolControllerphp yii anvol/Anvol product import
GardnersControllerphp yii gardners/Gardners ONIX feed
InsplayControllerphp yii insplay/Insplay API import
BuroomaailmControllerphp yii buroomaailm/Buroomaailm FTP import
EdrkControllerphp yii edrk/EDRK SOAP import
RaamatukoiControllerphp yii raamatukoi/Raamatukoi XML import
LasgoControllerphp yii lasgo/Lasgo product import
CustobarControllerphp yii custobar/Custobar marketing sync
KlaviyoControllerphp yii klaviyo/Klaviyo feed generation

Parallel Execution Scripts

Directory: console/scripts/

Bash scripts that run sync operations with parallel workers:

ScriptCommandWorkersItems/Worker
aws-product-image-sync.shsync/awsProductImageSync1030,000
aws-epub-sync.shsync/awsEPubFileSync1027,000
aws-drm-epub-sync.shsync/awsDrmEPubFileSync1020,000

The console/controllers/SyncController.php dynamically exposes actions for every handler in SyncHandlerFactory. Key NAV sync handlers include:

  • productSync, orderSync, availabilitySync, productPriceSync
  • clientSync, businessClientSync, categorySync, vendorSync
  • campaignSync, eanSync, giftCardSync
  • authorSync, salesTopSync, salesStatSync, salesHistorySync
  • wholesalePriceSync, countrySync, imageRepoSync

Run php yii help sync to see the full list of available handlers.