Appearance
Job Manager & Queue Processing
Flow ID: SY-22 | Module(s): job | Complexity: High Last Updated: 2026-04-04
Business Context
The Job Manager is the core orchestration system for all background task processing in Ecommercen. It implements a multi-queue job scheduling system where each queue (core, personalization, tracking, import, giftCards, erp, etc.) processes its registered commands according to cron schedules.
The system operates in two tiers:
- Job Manager (
AdvJobManager): Entry point called by the system cron. Spawns one subprocess per enabled queue in parallel. - Job Queue Manager (
AdvJobQueueManager): Per-queue processor. Initializes the schedule, picks the next job, executes it as a subprocess, handles retries and timeouts.
Each job is tracked in the job_schedule database table with status transitions: NOT_STARTED -> RUNNING -> FINISHED or FAILED.
API Reference
Health Check Endpoints
The application exposes Kubernetes-style health check endpoints (not part of the Job Manager itself, but relevant to system health monitoring):
| Method | Path | Description |
|---|---|---|
| GET | /_healthz/live | Liveness probe -- returns {"error":false,"version":"04.99.005.000"}. Confirms the application process is running. |
| GET | /_healthz/ready | Readiness probe -- checks DB connectivity, cache L1/L2 availability, and Solr status. Returns HTTP 500 if any dependency is unhealthy. |
Version format: MM.VV.PPP.CCC (e.g., 04.99.005.000) -- matches the format defined in application/config/version.php.
REST Endpoints
No REST API. Job management is CLI-only.
CLI Routes
| Route | Controller | Method | Description |
|---|---|---|---|
job_manager | AdvJobManager | index | Process all enabled queues in parallel |
job_manager/{queue} | AdvJobManager | index | Process a specific queue only |
job_queue_manager/{queue} | AdvJobQueueManager | index | Process next job in a specific queue |
CLI invocation: php cli.php job_manager (all queues) or php cli.php job_manager/core (specific queue).
Cron entry (typical): * * * * * php /path/to/cli.php job_manager -- runs every minute, each invocation processes one job per queue.
Code Flow
Job Manager: Queue Orchestration
- System cron triggers
php cli.php job_manager. AdvJobManager::index()receives optional$requestedQueueparameter.getQueues()builds the list of queues to process:- If a specific queue is requested, validates it exists in config and is enabled.
- Otherwise, collects all queues where
enabled = truefromapplication/config/jobs.php.
- For each queue, creates a
Symfony\Component\Process\Processinstance:php cli.php job_queue_manager/{queue} - Starts all processes in parallel via
$process->start(). - Blocks until all complete via
$process->wait().
Job Queue Manager: Per-Queue Processing
AdvJobQueueManager::index($queue)is invoked for a single queue.- Initialize schedule:
initializeJobs($queue):- Checks if any
JOB_NOT_STARTEDjobs exist for this queue. - If none exist and
hasScheduleris true, runsCreateJobScheduleto generate schedule entries fromcommandsconfig.
- Checks if any
- Lock check (if
lockJobsis true):- Calls
getRunningJob($queue)to check forJOB_RUNNINGjobs. - If a running job exists,
keepRunningJob()checks if it has exceeded its maximum allowed runtime (graceTime * (retryTimes + 1)). - If exceeded, cancels it (sets
JOB_FAILED). Otherwise, returns without processing (queue is locked).
- Calls
- Get next job:
getNextJob($queue)queriesjob_schedulefor the oldestJOB_NOT_STARTEDrecord whererun_at <= now(). - Execute job:
executeJob($nextJob, $queue, $jobCount): a. Checks if retry count exceeds configured max -- if so, marks asJOB_FAILED. b. Creates aSymfony\Component\Process\Process:c. Sets timeout fromphp cli.php job/job/{jobId}grace_time(per-job or per-queue or global default). d. Updates job status toJOB_RUNNINGwithstart_date. e. Runs the process synchronously with$process->run(). f. Retry loop: While not successful and retries remaining, waits 3 seconds and restarts. g. Timeout handling: CatchesProcessTimedOutException, increments retry count, recursively callsexecuteJob(). h. On success: marksJOB_FINISHEDwithend_date. i. On failure after all retries: marksJOB_FAILEDwithend_date.
Job Lifecycle
CreateJobSchedule generates entries
|
v
JOB_NOT_STARTED (status=0)
|
Queue Manager picks it
|
v
JOB_RUNNING (status=1)
/ \
/ \
v v
JOB_FINISHED JOB_FAILED
(status=3) (status=2)
|
retry? -> JOB_RUNNING againDomain Layer
No modern domain layer. Job management is fully legacy.
Architecture
| Component | Path | Purpose |
|---|---|---|
AdvJobManager | ecommercen/job/controllers/AdvJobManager.php | Queue orchestrator -- spawns parallel queue processors (56 lines) |
AdvJobQueueManager | ecommercen/job/controllers/AdvJobQueueManager.php | Per-queue job processor -- picks, executes, retries (151 lines) |
AdvJobsModel | ecommercen/job/models/AdvJobsModel.php | Model for job_schedule table (35 lines) |
Jobs_model | application/modules/job/models/Jobs_model.php | App-level wrapper |
JobStatus | ecommercen/job/libraries/JobStatus.php | Status constants (0-3) |
CreateJobSchedule | ecommercen/job/libraries/AdvCreateJobSchedule.php | Generates job_schedule entries from cron config |
ClearJobSchedule | ecommercen/job/libraries/AdvClearJobSchedule.php | Cleans up old completed/failed jobs |
| Jobs config | application/config/jobs.php | Queue definitions, commands, schedules |
| Routes | application/config/routes.php:630-640 | CLI route definitions |
Dependencies
- Symfony Process:
Symfony\Component\Process\Processfor subprocess management. - Symfony Process Exception:
Symfony\Component\Process\Exception\ProcessTimedOutExceptionfor timeout handling.
Data Model
job_schedule
| Column | Type | Description |
|---|---|---|
id | int (PK) | Auto-increment primary key |
job | varchar | Job command class name |
queue | varchar | Queue name (core, personalization, tracking, etc.) |
job_status | int | Status: 0=not_started, 1=running, 2=failed, 3=finished |
run_at | datetime | Scheduled execution time |
start_date | datetime (nullable) | When execution began |
end_date | datetime (nullable) | When execution completed |
grace_time | int (nullable) | Per-job timeout override (seconds) |
max_retries | int (nullable) | Per-job maximum retry limit override |
retry_count | int | Current retry attempt count |
options | text (nullable) | JSON-encoded job-specific options |
Configuration
Queue Configuration (application/config/jobs.php)
Global defaults:
graceTime: 60 seconds (default timeout per job)retryTimes: 0 (default retry count)
Per-queue settings:
| Queue | Enabled | Lock | Scheduler | Grace | Retries | Purpose |
|---|---|---|---|---|---|---|
core | true | true | true | - | - | Primary business jobs (orders, cache, sitemap, backup) |
personalization | false | true | true | 300 | 0 | Customer tagging and audience population |
tracking | true | false | true | - | - | Price tracking (runs every 5 min) |
import | false | true | false | 300 | 0 | Bulk data imports (no scheduler, on-demand) |
giftCards | true | false | true | - | - | Gift card processing |
erp | false | true | true | - | - | ERP integration jobs |
public_marketplace | false | true | true | - | - | Public marketplace order sync |
shopflix_marketplace | false | true | true | - | - | Shopflix marketplace order sync |
reporting | true | false | true | 1800 | 3 | Analytics reporting to external services |
fileManager | true | false | false | 300 | 0 | File processing (no scheduler, on-demand) |
Lock behavior:
lockJobs: true: Only one job at a time per queue. If a job is running, no new jobs start until it finishes or times out.lockJobs: false: Multiple jobs can run concurrently (each cron invocation processes the next available job).
Scheduler behavior:
hasScheduler: true:CreateJobSchedulegeneratesjob_scheduleentries based on cron expressions incommands.hasScheduler: false: Jobs are inserted intojob_scheduleby external code (e.g., admin triggers, webhook handlers).
Job Command Options
The commandOptions section maps each job class to its getOptions() return value, providing per-command configuration metadata. This is used by CreateJobSchedule to pass options to generated schedule entries.
Client Extension Points
- Custom commands: Add job command entries to queue
commandsarrays inapplication/config/jobs.php. - Custom queues: Add entirely new queue configurations for client-specific processing needs.
- Override grace times: Per-job
graceTimeandmax_retriesin the config override global defaults. - Job options: Pass
optionsarray to commands for client-specific parameters (e.g.,['days' => 5]forClearOldEmails). - Custom schedulers: Override
CreateJobScheduleto implement custom scheduling logic. - On-demand jobs: For queues with
hasScheduler: false(likeimport), client code directly inserts rows intojob_scheduleto trigger processing.
Business Rules
- Parallel queues: All enabled queues run in parallel via separate subprocesses, but jobs within a locked queue are sequential. (
ecommercen/job/controllers/AdvJobManager.php,index()) - Locking: Locked queues (
lockJobs: true) prevent concurrent job execution. A running job blocks the queue until it finishes or its maximum runtime is exceeded. (ecommercen/job/controllers/AdvJobQueueManager.php,keepRunningJob()) - Maximum runtime: Calculated as
graceTime * (retryTimes + 1). If a running job exceeds this, it is forcibly marked asFAILEDand the queue resumes. (ecommercen/job/controllers/AdvJobQueueManager.php,keepRunningJob()) - Retry with backoff: Between retries, the system waits 3 seconds (
sleep(3)) before restarting the process. (ecommercen/job/controllers/AdvJobQueueManager.php,executeJob()) - Timeout recovery: On
ProcessTimedOutException, the retry count is incremented and the job is re-executed recursively. (ecommercen/job/controllers/AdvJobQueueManager.php,executeJob()) - Schedule initialization: On each invocation, if no
NOT_STARTEDjobs exist for a queue, the scheduler regenerates the schedule from config. (ecommercen/job/controllers/AdvJobQueueManager.php,initializeJobs()) - Run-at ordering: Jobs are picked in
run_at ASCorder -- earliest scheduled job runs first. (ecommercen/job/models/AdvJobsModel.php,getNextJob()) - DB reconnect: The
AdvJobsModel::update()method calls$this->db->close(); $this->db->initialize()before updates to handle potential MySQL "gone away" errors during long-running jobs. (ecommercen/job/models/AdvJobsModel.php,update()) - Status constants:
JOB_NOT_STARTED=0,JOB_RUNNING=1,JOB_FAILED=2,JOB_FINISHED=3. (ecommercen/job/libraries/JobStatus.php) - On-demand queues: Queues with
hasScheduler: false(likeimport,fileManager) do not auto-generate schedules. External code inserts rows intojob_scheduleto trigger processing. (application/config/jobs.php) - Clear job schedule:
AdvClearJobSchedulepurges old completed/failed records per the queue'skeepLogPeriod(DateInterval). (ecommercen/job/libraries/AdvClearJobSchedule.php)
Related Flows
Core Queue Jobs
- SY-02 Order Status Emails -- email/SMS jobs on order status transitions
- SY-03 Incomplete Order Cancellation --
CancelIncompleteOrderscancels expired pending orders - SY-05 Sitemap Generation --
GenerateSitemapscreates XML sitemaps - SY-06 Solr Indexing --
SolrIndexupdates search index - SY-07 Cache Management --
ClearSiteCache/ClearCacheOnLimitmanage cache - SY-08 Database Backup --
BackUpDataBase/CleanBackUpsmanage backups - SY-13 Waiting List Notifications --
SendEmailForWaitingListstock alerts - SY-14 Order Reminders --
SendOrderReminderMailreminder emails - SY-15 Delivery Delay --
SendEmailForDeliveryDelaydelay alerts - SY-16 PayByBank Polling --
PayByBankGetStatuspayment status checks
Other Queue Jobs
- SY-04 Price Tracking --
TrackPricesruns in tracking queue - SY-09 Customer Data Jobs -- audience/tagging jobs in personalization queue
- SY-10 Loyalty Points Jobs -- points jobs in core queue
- SY-11 Review Reminders -- review request emails
- SY-12 Birthday Points Emails -- birthday greetings
- SY-17 Bulk Product Import -- product import in import queue
- SY-18 Image Upload ZIP -- image import in fileManager queue
System Infrastructure
- SY-01 Cron Framework -- high-level overview of the cron-based job system and all 59 job classes
- SY-24 Email Dispatch -- email infrastructure used by email-sending jobs
- SY-27 Deferred Tasks -- deferred task execution as an alternative to scheduled jobs
- SY-29 Deployment Architecture -- same jobs run on both Plesk and K8s deployment targets
Integration Flows
- IN-08 ERP Integrations -- ERP sync jobs in erp queue
- IN-04 Public Marketplace -- marketplace order sync in public_marketplace queue
- IN-03 Shopflix Marketplace -- Shopflix order handling in shopflix_marketplace queue
- IN-12 Analytics --
ReportingToDataboxin reporting queue
Wiki Guide: Job Manager Guide -- operational guide for the job scheduling system