drift Docs
Pages
drift Docs
Start
What is Drift?
The tour, if you are new here.
Use cases
Whether Drift does your thing.
Getting started
Nothing to deployed, in one command.
Architecture
How a slice is put together.
What it costs
The free grant, four unit prices, two rules.
Moving off Azure
Estimate, snapshot and transform a resource group.
Build
Canvas
Static sites, same origin as your API.
Tools
Operate
Auth
Route gates, API keys and your account.
Teams
More than one person on one account.
Security
Boundaries, sandboxing and hardening.
Troubleshooting
Error codes
What went wrong, and what to do about it.
Legal
Acceptable use
What a slice may not be used for.
Data processing
The DPA, and every sub-processor.

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:

Driftfile
slice "shop" {}

backbone {
  queue "orders" {
    depth = 1000
  }
}

atomic {
  backend "default" {
    function "QUEUE orders" {
      handler = "handle_order"
      memory  = "32MiB"
    }
  }
}
Python
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 interval500 ms, or the function's poll, from "50ms" to "60s"
Retries3, 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 failureThe invocation errored, or the handler returned a 5xx status.
ReachabilityRegistered under a synthetic queue method that no HTTP request can match, so a queue handler has no URL.
BookingThe 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:

Driftfile
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:

JSON
{ "fired_at": "<RFC 3339 timestamp>", "schedule": "0 2 * * *" }

Anything else the handler needs comes from secrets or Backbone.