Skip to the page

Feature by feature

Chapter 6 of 11

Actions, jobs and webhooks

External code, background jobs and webhooks run under the same caller rules and commit boundaries as your queries. Gatekeeper queries guard handlers and jobs commit alongside writes, while the change log feeds warehouses without polling.

Queries and live subscriptions keep state inside PostgreSQL, while production apps also send emails, run delayed tasks and sync analytics warehouses. Moving work outside a database query should not bypass caller policies or fire on rolled-back data.

In practice

An action runs a gatekeeper query under the caller’s identity before invoking external code. If Ben calls emailNote with the ID of Ada’s private note, PostgreSQL returns zero rows and Napalm responds with 403 nothing_found without waking the handler. When Ada calls emailNote on her note, the handler receives the permitted row and sends the email.

Actions and hosted handlers#

Pillar at work: Caller-bound

An action pairs a saved .edgeql query with handler code written in TypeScript, Python, Go, Rust or Dart. PostgreSQL executes the query first under the caller’s access policies, and Napalm invokes the handler only when at least one permitted row matches.

Gatekeeper query

PostgreSQL checks the paired query first and blocks unauthorized calls.

On-demand handlers

Handlers wake per call and hold no standing database password.

Because the gatekeeper query runs under global caller, unauthorized requests fail inside PostgreSQL before waking external code.

dbschema/queries/emailNote.edgeql
select Note { title, body }filter .id = <uuid>$note
The gatekeeper query loads the note under the caller’s select policy before any handler wakes.

When a handler needs to write results back, exchanging its call token yields a 60-second session scoped to the original caller. Place a matching file in handlers/ to run on Napalm’s serverless runtime, or point the action at your own HTTPS endpoint.

Terminal
# handlers/emailNote.ts pairs with dbschema/queries/emailNote.edgeqlnapalm handlers deploy notes
Deploy hosted handlers in TypeScript, Python, Go, Rust or Dart.

Jobs and cron schedules#

Pillar at work: Commit-atomic

Enqueueing work on a separate broker from an HTTP handler can lose jobs on a crash or run jobs after a database rollback. In Napalm, background jobs are rows in ext::napalm::Job that commit in the same statement as your writes.

dbschema/queries/addNoteWithReminder.edgeql
with  note := (insert Note { owner := global caller, title := <str>$title, body := <str>$body }),  reminder := (insert ext::napalm::Job {    query := 'sendReminder',    variables := <json>(note := <str>note.id),    run_time := datetime_of_statement() + <duration>'24 hours',  }),select note { id }
Inserting a Note and queueing its 24-hour reminder commit or roll back together.

Rolled-back transactions leave no job behind. When run_time arrives, the job executes under the caller’s identity and carries a stable job ID across retries so handlers can deduplicate outbound calls.

Transactional jobs

Job rows commit alongside your writes and run asynchronously as the original caller.

Recurring tasks without a user session, such as daily digests or rollups, run on cron schedules under a dedicated service key.

Terminal
napalm schedules add notes sendDigest '0 8 * * *' --key <key-id>
Schedule sendDigest daily at 08:00 UTC under a scoped service key.

Commit notifications and webhooks#

External receivers watching changes to a type need no polling loop. Add a notify declaration on the schema type to emit an event whenever a transaction commits an insert, update or delete.

dbschema/default.gel
type Note {  required owner: ext::auth::Identity;  multi editors: ext::auth::Identity;  required title: str;  required body: str;  # …search indexes and access policies   notify note_changed after insert, update, delete;}
Declare a post-commit notification event directly on the schema type.

Subscribed HTTPS endpoints receive an HMAC-signed ping containing the commit’s Napalm-Position bookmark as soon as the write commits. Rolled-back transactions and dry runs send nothing.

Reading the change log#

Pillar at work: Compiled

Every committed write appends to the branch’s ordered change log. From a terminal, napalm changes summarizes recent commits with an org token without exposing row values.

Your terminal
napalm changes notes --since 1h
2026-11-16 09:14 PST session 8f2c1e64 Note (1 added)
2026-11-16 09:18 PST session 8f2c1e64 Note (1 updated)
2026-11-16 09:22 PST key 0b6f1f5e Note (2 updated)
Each entry records commit time, caller kind, short credential ID and affected row counts.

When a webhook ping wakes your sync worker, passing Napalm-Position as reach alongside the worker’s stored cursor guarantees the response includes the commit that triggered the ping, even when served by a read replica. Every row returned by GET /changes is filtered through the caller key’s select policies.

Terminal
curl "https://notes.napalmdata.com/changes?since=2026-11-08T00:00:00Z&types=Note&limit=100" \  -H "Authorization: Bearer $NAPALM_KEY"
Fetch the next policy-filtered page of changes from a saved cursor.

Warehouse sync#

Issue a dedicated read-only service key so your analytics or lakehouse worker can pull permitted changes without write privileges.

Terminal
napalm keys create notes --label warehouse --read-only
Create a read-only service key for downstream warehouse sync.

After an initial table copy, the worker pages forward from its saved cursor as webhook pings arrive. Applying a page is idempotent by primary key, and if a worker stays offline longer than your branch’s log retention, a gap marker instructs it to run a fresh copy. Each JSON change item also records how the write arrived (http, mcp, job or schedule).

So far every record has belonged to an individual user. Multi-tenant apps add shared workspaces, role hierarchies, usage ledgers and shard roots.

Type a word or two to search every docs page.