Run SQS-style pull queue workers with zero-secret workload identity
Long-running workers consume Gregale queues without an HTTP listener using `leases`, `ack`, `nack` and `extend`, preview SDK auto-heartbeating (`consumeQueue`), `queue_depth` autoscaling and `gregale:queues` workload tokens that block staging/preview code.
Consume background job queues from long-running workers with no HTTP listener using pull queue leases, automatic lease heartbeats, queue_depth autoscaling, and zero-secret workload identity. On Gregale, worker loops long-poll for batches, process jobs cleanly on SIGTERM, and block staging or PR preview code from touching production queues.
Maturity note: Pull queue HTTP lease endpoints run on production queues today. SDK pull consumers live under preview paths (
@gregale/sdk-node/preview/queues/runtime,faas_sdk.preview.queue_consumer, and GoClient.ConsumeQueue), and pull bindings are not yet supported on staging environments (use push on staging). Workload-identity queue auth requires platform workload identity to be enabled on your installation (otherwise pass an API key withqueues:consume).
Why push queues and DIY SQS consumers add friction
HTTP push queues require every ML, video-transcoding, or batch worker to run and secure an HTTP server just to receive deliveries. Moving to AWS SQS fixes that, but forces you to manage IAM credentials inside containers, build visibility-timeout renewal loops so slow jobs do not get redelivered mid-flight, and coordinate autoscaling scale-in so active jobs are not killed mid-batch.
Lease, heartbeat, and drain with SDK or HTTP pull bindings
Create a pull queue binding on the worker app and pair it with a queue_depth scaling target:
curl -X POST "$GREGALE_API_URL/v1/apps/my-worker/queue-bindings" \
-H "Authorization: Bearer $KEY" \
-d '{"name":"jobs","queue_name":"jobs","mode":"pull","workload_class":"worker","max_concurrency":4}'
With the Node (consumeQueue), Python (consume_queue), or Go (Client.ConsumeQueue) consumers, Gregale long-polls up to 20 seconds per lease request, automatically extends each lease every third of its visibility timeout while the handler works, passes a cancellation signal (AbortSignal in Node, message.lease_lost in Python) if a lease drops, retries failed ack/nack calls, and stops leasing new messages on SIGTERM so in-flight work finishes inside the stop grace window:
import { consumeQueue } from '@gregale/sdk-node/preview/queues/runtime';
consumeQueue({ app: 'my-worker', queue: 'jobs', concurrency: 4 }, async (message, { signal }) => {
await resize(message.payload, { signal });
});
Direct HTTP clients can drive leases (wait_seconds up to 20), leases:ack, leases:nack (with optional delay_seconds), and leases:extend directly.
Zero-secret workload identity and scale-in protection
Inside a Gregale microVM, workers authenticate with a short-lived workload-identity token for audience gregale:queues from the guest's loopback token endpoint:
- No API keys in images: Production workers never embed long-lived queue tokens in
envor Docker layers. - Strict production-only guard: Only production deployments can lease with their workload token—staging or PR preview deployments receive
401, guaranteeing unreviewed branch code cannot drain production queues. - Lease-aware scale-in: Gregale tracks which worker instance holds each lease so pool scale-in avoids stopping busy instances mid-message. If an instance crashes or hits a network partition, its active leases terminate immediately for redelivery.
Limits and operational tradeoffs
- Batch and visibility bounds: One call leases up to
100messages or8 MiBof payloads and headers (leases:ack/nack/extendaccept up to100receipts), with up to64concurrent waiting long-poll calls per API server per account. Default visibility timeout is30seconds, capped by the plan's async invocation deadline; leases exceeding their attempt budget move to dead letters withqueue_lease_attempts_exhausted. - At-least-once semantics and staging: Handlers must be idempotent, staging environments must use push bindings rather than pull today, and workers running outside Gregale still authenticate with a scoped
queues:consumeAPI key.
See Pull queue leases, Event-driven workloads, Tune scaling, Running a Node.js API and a worker together, and Gregale pricing.
Questions
- How do pull queue workers authenticate without storing API keys in the image?
Workers inside a Gregale microVM fetch a short-lived workload-identity token for
gregale:queuesfrom the guest loopback endpoint (where workload identity is enabled), keeping long-lived keys out of images.- Can a staging deploy or PR preview accidentally drain production queue jobs?
No. Workload-identity queue leases only succeed for production deployments; staging or preview apps receive
401if they try to lease production messages.- What happens if a worker scales in or crashes mid-message?
The platform tracks lease ownership to avoid stopping busy instances first during scale-in, and if an instance stops or fails, its leases end so messages redeliver cleanly.