Zuverlässige Hintergrund- und Zeitplanjobs
Macht Hintergrundarbeit bei Deployments wiederaufnehmbar und schützt Geschäftsaktionen vor überlappenden Zeitplänen und mehrfacher Zustellung.
workers-scheduled-operations
Agenten mit diesem Skill
Wann ist der Skill hilfreich?
Nutze diesen Skill, wenn Releases Jobs unterbrechen, geplante Berichte überlappen oder fehlgeschlagene Nachrichten kontrolliert wiederhergestellt werden müssen.
Wobei hilft er dir?
- Beendet neue Arbeitsannahme beim Herunterfahren und begrenzt Abschluss oder Übergabe laufender Jobs.
- Schützt wiederholte Aktionen und Zeitpläne bei kompatibler Zusammenarbeit verschiedener Versionen.
- Plant begrenzte Wiederholungen, einsehbare Fehlerwarteschlangen und aussagekräftige Worker-Zustandssignale.
Das könntest du fragen
Bereite unseren Berichtsworker auf Deployments vor. Laufende Arbeit soll fertig werden oder fortsetzbar bleiben; Zeitplanüberschneidung und erneute Zustellung dürfen keine doppelten Ergebnisse erzeugen. Sende beim Berichtserstellen Shutdown und starte den nächsten geplanten Versuch. Prüfe ein Endartefakt, begrenzte Übergabe und keine parallele Verarbeitung desselben Zeitraums.
Ausführliche Dokumentation
Hier findest du die ursprüngliche Anleitung, Beispiele und Prüfschritte des Skills in ihrer Originalsprache.
Weniger anzeigen
Workers & Scheduled Operations
Background workers and scheduled cron jobs execute critical business side effects out of sight of HTTP load balancers. If they are killed mid-job during deployments or run concurrently without locks, they silently corrupt state or duplicate external actions.
Graceful Shutdown & Drain Lifecycle
When deploying a new version or scaling down a worker node:
- Stop pulling new work immediately on
SIGTERM/SIGINT:- Close the queue consumer subscription so no new jobs are dequeued while the worker is shutting down.
- Finish in-flight jobs within a bounded drain window:
- Configure the process supervisor (
stop_grace_periodin Docker/Compose,terminationGracePeriodSecondsin Kubernetes,kill_timeoutin Fly/systemd) to exceed the maximum normal job execution time (e.g., 30s–120s). - If a job cannot finish before the grace deadline, checkpoint its progress, release its lease cleanly so another worker can resume, and exit before
SIGKILL.
- Configure the process supervisor (
- Separate worker health checks from HTTP server checks:
- A worker process with no HTTP server still needs a liveness/heartbeat signal (e.g., updating a local heartbeat timestamp file or
/healthzsocket only after the consumer loop tick succeeds and Redis/broker connection is healthy).
- A worker process with no HTTP server still needs a liveness/heartbeat signal (e.g., updating a local heartbeat timestamp file or
Idempotency, Concurrency & Mixed-Version Rollouts
- Design every job and cron task to be idempotent:
- Queue brokers guarantee at-least-once delivery, and cron schedulers can fire twice during clock skew or leader election. Key external side effects (emails, charges, webhooks, DB writes) by a deterministic idempotency key or status transition guard (
WHERE status = 'pending').
- Queue brokers guarantee at-least-once delivery, and cron schedulers can fire twice during clock skew or leader election. Key external side effects (emails, charges, webhooks, DB writes) by a deterministic idempotency key or status transition guard (
- Prevent overlapping cron executions:
- Use a distributed lock with a bounded TTL (
SET resource val NX EX ttlor Postgres advisory lock) or schedulerconcurrencyPolicy: Forbidso a slow 6-minute report job scheduled every 5 minutes does not pile up 20 concurrent overlapping runs.
- Use a distributed lock with a bounded TTL (
- Cross-version payload compatibility during deploys:
- During a deployment, Version $N+1$ of the web app may enqueue jobs that are picked up by a still-running Version $N$ worker (or vice versa). Never rename or remove required job payload fields in a single step: add new optional fields first, deploy workers that understand both old and new shapes, and remove legacy fields in a later release.
Dead-Letter Queues (DLQ) & Backpressure
- Enforce bounded retry counts with exponential backoff + jitter (
attempt 1..N), and route poison-pill messages that exhaust retries to an inspectable Dead-Letter Queue (DLQ) with the failure reason, stack trace, and payload metadata preserved for replay once fixed.
Enthaltene Dateien 1
SKILL.md
