Triggers
An HTTP route is one way to reach a function. A queue and a schedule are the other two, and neither needs a caller: the slice invokes the function on your behalf.
Queue-triggered functions
A function doesn't have to be called over HTTP. Label the function "QUEUE orders", naming the queue it drains, and the slice polls that Backbone queue on your behalf. The queue block beside it declares the queue and how deep it may grow:
slice "shop" {}
backbone {
queue "orders" {
depth = 1000
}
}
atomic {
backend "default" {
function "QUEUE orders" {
handler = "handle_order"
memory = "32MiB"
}
}
}def handle_order(body, req):
# body is the message that was pushed onto the "orders" queue
drift.backbone.nosql.collection("orders").insert(body)
return 200, "OK", {"stored": True}A queue handler takes the body shape, (body, req), and the popped message is the body. It returns the same three (or four, in Go) values an HTTP handler does.
| Behaviour | Value |
|---|---|
| Poll interval | 500 ms, or the function's poll, from "50ms" to "60s" |
| Retries | 3, or the function's max_retries, from 1 to 100. A failed message is requeued with its retry count; once exhausted it moves to <queue>-dlq. |
| What counts as a failure | The invocation errored, or the handler returned a 5xx status. |
| Reachability | Registered under a synthetic queue method that no HTTP request can match, so a queue handler has no URL. |
| Booking | The slice books it under the queue's name (queue:orders) with the memory the function declares, exactly like an HTTP function. |
Write poll and max_retries inside the function "QUEUE orders" block to change the first two, for example poll = "250ms" and max_retries = 5; they are refused on a function that is not a queue function. The queue's depth is depth on the queue block (a queue that leaves it out takes the slice's limits.queue_depth). There is no command that registers a queue trigger: the label is the registration, and drift apply deploys it. Since any HTTP function has a public URL, a POST function is your webhook receiver. Point Stripe, GitHub or your provider straight at it.
Scheduled functions
A schedule is not an identity: it is something a function also does. Give any function a cron and it runs on that schedule in addition to its own trigger. Same code, two ways in:
slice "shop" {}
atomic {
backend "default" {
function "POST /nightly-rollup" {
handler = "PostNightlyRollup"
memory = "32MiB"
cron = "0 2 * * *" # 02:00 daily, and still callable over HTTP
}
function "POST /hourly-cleanup" {
handler = "PostHourlyCleanup"
memory = "32MiB"
cron = "0 * * * *"
}
}
}Standard 5-field POSIX cron: minute hour day-of-month month day-of-week. Seconds and the 6-field quartz format are not supported. The schedule registers as part of the deploy, with no post-deploy step. The slice's allowance of scheduled jobs is limits.scheduled_jobs; a file that leaves it out gets one per function with a cron (two above), the fewest that runs them. The free slice allows one scheduled job, so a file with more is priced, and drift plan says so.
Each fire delivers a small JSON body, so a scheduled handler takes the body shape:
{ "fired_at": "<RFC 3339 timestamp>", "schedule": "0 2 * * *" }Anything else the handler needs comes from secrets or Backbone.