Skip to the page

Feature by feature

Chapter 6 of 11

Actions, jobs and webhooks

Side effects run only when permitted records save. Actions, background jobs and an ordered change log connect emails, webhooks and warehouses without polling.

Sending emails, queueing background work and syncing a warehouse usually force bad trade-offs. Workers holding broad database keys can act on records the caller cannot see. Jobs queued before a rollback fire on data that never saved, and warehouse connectors either bypass schema policies or poll tables on a timer.

In practice

Napalm guards external code with a saved query inside PostgreSQL before your handler ever wakes up. When Ben calls emailNote with the ID of Ada’s private note, he receives a 403 nothing_found error, and no email code runs. When Ada calls emailNote on that same note, the email goes out.

Actions and hosted handlers#

Pillar at work: Caller-bound

An action solves the permission problem by pairing a saved query with your handler code. PostgreSQL runs the query first under the caller’s access, and Napalm invokes your handler only when permitted records match.

dbschema/queries/emailNote.edgeql
select Note { title, body }filter .id = <uuid>$note
When access rules hide the note from the caller, the handler never runs.

On-demand action handlers

Handlers wake on demand and exchange the ES256 call token via call.db() for a 60-second session bound to the caller.

Query-guarded admit or refuse

PostgreSQL runs the saved query first under global caller, admitting matching rows or refusing with 403 nothing_found before the handler wakes.

The handler holds no standing database key. To write a result back, the handler exchanges the call token for a 60-second session bound to that same caller. Put a matching file in handlers/ so Napalm deploys and runs the code on demand and sleeps between calls, or point the action at your own HTTPS server.

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

Jobs and schedules#

Pillar at work: Commit-atomic

Pushing to an external queue from an HTTP route risks losing jobs on a crash or running jobs after a rollback. In Napalm, jobs are records in ext::napalm::Job that commit together with user writes and run only after the transaction finalizes.

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 }
The note and the reminder save together or fail together.

Commit-atomic background jobs

ext::napalm::Job records commit atomically alongside user writes and execute as the original caller only after finalization.

A failed write leaves no queued job behind. When the scheduled time arrives, the job runs as Ada and retries carrying the same job id so your handler never sends the same email twice. Scheduled tasks without a user session, such as a morning digest, run on cron under a scoped service key.

Terminal
napalm schedules add notes sendDigest '0 8 * * *' --key <key-id>
Run sendDigest every day at 08:00 UTC under a given service key.

Notify and webhooks#

Downstream systems that watch every change to Note need no polling loop either. Declare a notify line on the type so Napalm notifies subscribers whenever a write saves.

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 rules   notify note_changed after insert, update, delete;}
One line in the schema names the post-save change event.

Subscribed HTTPS webhooks receive a signed ping carrying a causal Napalm-Position bookmark as soon as an insert, update or delete on Note commits. Rolled-back writes send nothing.

Reading the change log#

Pillar at work: Compiled

Every saved insert, update and delete appends to an ordered branch change log. From the CLI, one command summarizes recent transactions without exposing field 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 saved transaction lists the commit time, the caller kind and short id and the record counts per type.

Commit-ordered change log

Every commit appends caller kind, short ID and mutated type counts to an ordered log queried via Napalm-Position bookmarks.

When a webhook ping arrives, your worker passes that Napalm-Position as reach alongside its saved cursor and sees every write covered by the ping, even when a replica answers. No connection stays open between writes, and Napalm compiles your schema’s access rules into every page read.

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

Warehouse sync#

Create a dedicated read-only service key so your warehouse worker reads permitted changes without writing back.

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

After one initial copy, the worker applies each new page as changes save. Re-applying a page overwrites the same warehouse rows without harm, and if a bookmark falls behind log retention, the worker starts a fresh copy cleanly. In JSON change pages, each entry also records how the write arrived, such as http from the app, mcp from an agent or job from background work.

Ada’s personal app handles live screens, background jobs and change streams. Now whole customer companies want workspaces, roles and usage billing.

Type a word or two to search every docs page.