Imported from zapPilot/zapEngine (
apps/account-engine/src/modules/jobs/AGENTS.md). Install upstream withnpx skills add zapPilot/zapEngine --skill jobs. Copyright stays with the author.
See @../../../AGENTS.md for app-level conventions.
Jobs module
In-memory async work queue and processors for weekly reports, per-user daily decision packets, and strategy-change notifications.
Flow
- A route creates a job with
jobQueueService.createJob(...). job-processor.service.tspolls the in-process queue and dispatches to a registered processor.- Processors return
JobProcessingResult; retryable failures are rescheduled with backoff and permanent failures are marked failed. - Weekly-report batch jobs fan out into single-user child jobs;
GET /jobs/:jobIdderives parent status from the children. STRATEGY_CHANGE_BATCHdeliberately does not fan out — it broadcasts one strategy-wide message, so there is nothing per-user to compute.DAILY_SUGGESTION_BATCHrequires explicit non-emptyuserIdsand fans out one live suggestion job per operator. It must never auto-discover recipients.
Invariants
- Processors must be idempotent because retries can execute them again.
- Return
{ success: false, error }orcreateJobFailureResult; never swallow errors as successful results. - Keep status transitions and job logs in
JobQueueService. - Register new processors in
container.ts; add job types and payloads ininterfaces/job.interface.ts.
Operational gotchas
- Jobs, child relationships, and logs are process-memory only. There is no durable
job_runs, leasing, or dead-letter storage. - Restarts, deploys, crashes, auto-stop, or requests hitting another machine can lose a job or make
GET /jobs/:jobIdreturn 404. - Permanent failures handled by
JobProcessorServicesend fire-and-forget email throughAdminNotificationService; they are not Telegram alerts. - Cleanup force-fails stale in-memory jobs but does not invoke the normal admin failure notification.
- Keep the external Pipedream weekly-report completion watchdog until queue/status storage becomes durable across restarts and machines.
