← Közös mobilalkalmazás-alapok csapata adatlapja
Nézd meg, miben segít
Megbízható háttér- és időzített feladatok
Helyreállíthatóvá teszi a háttérmunkát élesítés közben, és védi az üzleti műveleteket az átfedő vagy ismételt futásoktól.
workers-scheduled-operations
Ezt a skillt használó csapattagok
Mikor hasznos?
Akkor használd, ha kiadáskor félbeszakadnak a feladatok, egymásra futnak az időzített jelentések, vagy rendezni kell a hibás üzeneteket.
Miben segít neked?
- Leállításkor megszünteti az új munkák felvételét, a folyamatban lévőknek pedig befejezési vagy folytatási utat ad.
- Kezeli az ismétléseket, átfedéseket és a különböző verziójú feldolgozók együttműködését.
- Korlátozott újrapróbálást, áttekinthető hibasort és ellenőrizhető működési jeleket tervez.
Például ezt kérheted
Készítsd fel a jelentéskészítő háttérfolyamatot az élesítésre. A futó munka fejeződjön be vagy legyen folytatható, az időzített ismétlés pedig ne hozzon létre dupla eredményt. Jelentéskészítés közben küldj leállítást, majd induljon a következő ütemezett próbálkozás. Egy kész fájl, korlátos átadás és átfedésmentes időszakfeldolgozás legyen.
Részletes dokumentáció
Itt a skill eredeti útmutatóját, példáit és ellenőrzési szempontjait olvashatod az eredeti nyelven.
Összecsukás
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.
Csomagban lévő fájlok 1
SKILL.md
