# cron-and-queues

Scheduled jobs that don't overlap or vanish: cron/systemd timers with locks, idempotent state, run logs

- **Space:** always-on-agents-public (https://github.com/Tech-Realm/space-always-on-agents-public/tree/main/cron-and-queues)
- **Level:** L2 (as the registry reports it)
- **Keys it needs (names only):** none
- **Tools:** python3
- **Routes:** self-hosted; checks: 1
- **Uses:** new (no recorded use yet)
- **Install:** `logicpacks pack use always-on-agents-public/cron-and-queues` or MCP `get_pack always-on-agents-public/cron-and-queues`
- **Files:** CHANGELOG.md, code/run_once.py, outcome/EVIDENCE.md, outcome/checks.yaml, outcome/results.json, pack.yaml, spec/SPEC.md, spec/source.md

## Purpose (spec/SPEC.md)

## Goal

Recurring jobs (scrapes, syncs, reports) run on schedule, never overlap, survive reboots, record each run, and are safe to re-run.

## Steps

1. Prefer systemd timers (Persistent=true catches missed runs) or launchd StartInterval on the Mac; cron only where nothing else exists.
2. Wrap the job with a lock: `flock -n /run/lock/job.lock job.sh` (Linux) or the Python lock in code/run_once.py (portable).
3. Make the job idempotent: keep a state file of processed ids; write output atomically (tmp + rename).
4. Log each run (start, end, result) to a JSON-lines file; a watchdog alerts if the last success is too old.
5. For bursts of work, a simple SQLite queue table (status, attempts, next_run_at) beats an external queue SaaS.

## Edge cases

- Two schedulers (cron + timer) for the same job = duplicate runs.

## Don'ts

- Don't let a job run forever: always set a timeout.
- Never put a password, token or key value in this pack: use the env NAMES in pack.yaml and `lp key add NAME`.



---

Canonical URL: https://logicpacks.io/packs/always-on-agents-public/cron-and-queues

Developed by TechRealm (techrealm.online), the software team. Operated by Al Jash Trading (Establishment), Abu Dhabi, since 1994, the legal entity that hosts and is responsible for the service. Economic licence CN-1030597, Abu Dhabi Registration Authority. Address: Office 5, Bani Yas West 4, Bani Yas, Abu Dhabi, UAE. Website: https://aljashtrading.com. Contact: hello@logicpacks.io, security@logicpacks.io, WhatsApp +1 713 632 2262 (https://wa.me/17136322262).

Machine-readable index: [/llms.txt](/llms.txt). Plain facts: [/about.md](/about.md). Safety: [/safety.md](/safety.md).
