Events
Call a Function or start a Workflow run when something happens, on a schedule, on a new object in a Bucket or on a row change in a SQL database, and handle the deliveries that fail.
Usage
An EventSource turns something that happens into events: a timer, a new object in a Bucket, or a row change in a SQL database. A Sensor subscribes to events and runs an action for each one: it calls a Function, or starts a Workflow run.
The first example calls the Function log-burst every 10 seconds. Each call leaves an
Invocation, funcd's record of the action.
Install the dev build of funcdctl and Git, and put Node.js, or Python 3.12 or later
as python3, on the PATH. Save this manifest as ticker.yaml in the example's folder, which funcdctl dev applies
in the namespace default:
apiVersion: funcd.io/v1alpha1
kind: EventSource
metadata:
name: ticker
namespace: default
resourceGroup: rg1
spec:
timer:
events:
- name: tick
interval: 10s
---
apiVersion: funcd.io/v1alpha1
kind: Sensor
metadata:
name: burst-on-tick
namespace: default
resourceGroup: rg1
spec:
on:
- name: tick
source: ticker
event: tick
do:
- name: burst
on: tick
function: log-burstThe first tick comes 10 seconds after the EventSource's creation. An action calls one function or starts one
workflow, never both. The Function receives each event as a CloudEvent whose data, {} for a timer, funcd
checks against the Function's contract. An Invocation is Ready once the
Function answers without an error, or Failed once the delivery ends as a
dead letter, and never changes after.
Clone the repository:
$ git clone https://github.com/pyvvo/funcd-typescript
$ cd funcd-typescriptSave the manifest as examples/log-burst/ticker.yaml and start the example:
$ funcdctl dev examples/log-burst --cport 8081About 10 seconds later, list the Invocations from another terminal until one appears:
$ funcdctl --server http://127.0.0.1:8081 --token funcd-dev-token get invocations -n default
NAME
inv-fc98965dbd0db0765f25Its status.phase is Ready:
$ funcdctl --server http://127.0.0.1:8081 --token funcd-dev-token get invocation inv-fc98965dbd0db0765f25 -n default -o jsonThe call's ERROR records appear after a moment; times and order vary:
$ funcdctl --server http://127.0.0.1:8081 --token funcd-dev-token logs log-burst -n default --severity error
2026-11-13T18:08:00.944Z [ERROR] 0 item failed
2026-11-13T18:08:00.944Z [ERROR] 0 burst stderr default
2026-11-13T18:08:00.945Z [ERROR] 0 item failed
2026-11-13T18:08:00.945Z [ERROR] 0 item failed
2026-11-13T18:08:00.946Z [ERROR] 0 item failedPress Ctrl-C in the first terminal to stop.
Run on a schedule
A timer event sets one schedule:
interval, from 100 milliseconds to 24 hours, fires at each whole interval since the EventSource's creation, so its times survive a restart.cron, five fields or a macro such as@daily, is read in the IANA time zone oftimeZone, or in UTC.
apiVersion: funcd.io/v1alpha1
kind: EventSource
metadata:
name: schedules
namespace: default
resourceGroup: rg1
spec:
timer:
events:
- name: every-minute
interval: 1m
- name: nightly
cron: "30 2 * * *"
timeZone: Europe/ParisA timer does not catch up a tick missed while funcd was stopped, and carries no data: pass values through the action's input. A Sensor can also start a Workflow run on a schedule.
React to a new object in a Bucket
A blob event fires once for each new object under its prefix in a
Bucket of the namespace, and again when an object is written with another size or modification
time; a deletion fires nothing. funcd lists each prefix every
eventing.blobPollInterval, 15 seconds by default, so an event can lag
that long. The data holds bucket, the full key, size, version and time. funcd records the keys that each event
has fired for; when the EventSource is created or a prefix changes, the objects already there fire too, but only to the
Sensors subscribed at that moment.
From the funcd-typescript repository, start the s3-roundtrip example; the steps also need curl:
$ funcdctl dev examples/s3-roundtrip --gport 8080 --cport 8081In another terminal, write an object, then list the runs until one appears, about a second later:
$ curl -s -X POST -H 'content-type: application/json' -d '{"inv":"001"}' http://127.0.0.1:8080/function/s3-roundtrip
{"put":true,"get":true,"list":1,"denied":false,"granted":true}
$ funcdctl --server http://127.0.0.1:8081 --token funcd-dev-token workflow runs
NAME
gold-ingest-run-7634b281Read the run until its phase is Succeeded, Failed or Cancelled:
$ funcdctl --server http://127.0.0.1:8081 --token funcd-dev-token workflow describe gold-ingest-run-7634b281
RUN gold-ingest-run-7634b281 phase: Succeeded
echo phase: Succeeded duration: 0s
trace: bb7489fb793dbffa27e039f4b2cf3408
full logs: funcdctl workflow logs gold-ingest-run-7634b281The run's input holds the object's key:
$ funcdctl --server http://127.0.0.1:8081 --token funcd-dev-token get workflowrun gold-ingest-run-7634b281 -n default -o jsonEach new write, the same tag again included, starts another run. Press Ctrl-C in the first terminal to stop.
The EventSource, in drop-source.yaml:
# gold-drops fires arrived for each new or rewritten object under gold/ of the Bucket lakehouse.
apiVersion: funcd.io/v1alpha1
kind: EventSource
metadata:
name: gold-drops
namespace: default
resourceGroup: rg1
spec:
blob:
bucket: lakehouse # the Bucket of bucket.yaml
events:
- name: arrived # the CloudEvent `type`
prefix: gold/ # only objects under gold/, the prefix s3-roundtrip owns, fire
on:
- CreatedThe Sensor, in drop-sensor.yaml, starts the Workflow
ingest, whose one
built-in step returns its input:
# gold-ingest starts an ingest run for each object that gold-drops reports, with its key as input file.
apiVersion: funcd.io/v1alpha1
kind: Sensor
metadata:
name: gold-ingest
namespace: default
resourceGroup: rg1
spec:
on:
- name: dropped
source: gold-drops
event: arrived
do:
- name: run
on: dropped
workflow: ingest
input:
file: "${{ event.data.key }}"A workflow action succeeds once funcd creates the run; a later failure shows in the run's phase, not as a dead letter.
React to a row change in a SQL database
A sql event fires on the changes that on lists, Insert, Update or Delete, all
three by default, to one table of a SQLDatabase of the namespace, matched exactly. The database's engine reports them
to funcd: its change feed. The data holds op, table, rowId, index, the commit number that a commit's
changes share, and before, after and commitTimestamp when the change carries them. Past 256 KiB together, funcd
drops before and after and sets truncated to true. The SQL page runs this Python
example.
The EventSource and the Sensor, in examples/sql-orders/changes.yaml:
# The change feed of orders-db: every insert, update and delete of table orders fires order-changed,
# and the Sensor hands the change to the audit function.
apiVersion: funcd.io/v1alpha1
kind: EventSource
metadata:
name: orders-changes
namespace: default
resourceGroup: rg1
spec:
sql:
database: orders-db
events:
- name: order-changed
table: orders
---
apiVersion: funcd.io/v1alpha1
kind: Sensor
metadata:
name: orders-audit
namespace: default
resourceGroup: rg1
spec:
on:
- name: changed
source: orders-changes
event: order-changed
do:
- name: record
on: changed
function: auditThe handler of audit:
"""The audit function: a Sensor calls it with each change of table orders that the change feed of orders-db
delivers, and it records the change in table order_events."""
from typing import Any, TypedDict
from funcd_shim import CloudEvent, FunctionContext
from orders_core.models import OrderEvent
from orders_core.sqlrun import execute
from sqlmodel import insert
class Change(TypedDict, total=False):
op: str
table: str
rowId: int
before: dict[str, Any]
after: dict[str, Any]
index: int
class FuncOutput(TypedDict):
recorded: int
def handle(context: FunctionContext, event: CloudEvent[Change]) -> FuncOutput:
change = event.get("data") or {}
row = change.get("after") or change.get("before") or {}
execute(
context,
insert(OrderEvent).values(
order_id=change.get("rowId", 0),
change_index=change.get("index", 0),
change=change.get("op", ""),
status=row.get("status"),
),
)
return {"recorded": 1}Shape the input of an action
An action without an input passes the event's data as it is. An input replaces it with a
JSON object whose top-level values are literals, or strings that hold one expression between ${{ and }} reading
event.data and its paths, event.id, event.source, event.type or event.time.
funcd checks each input when the Sensor is applied: an input that is not a JSON object, or an expression that does
not parse or reads a field that no event has, leaves the Sensor not Ready with the reason InvalidInput, and none of
its actions runs. The input becomes the CloudEvent's data for a function action, checked against the Function's
contract, and the run's input for a workflow action, checked when the run starts; a run whose input does not match,
or exceeds workflow.payloadLimit bytes, fails at its start.
Read the event in the handler
The handler receives the event as its second argument, a CloudEvent with specversion, id, source
(funcd://<namespace>/eventsource/<name>), type, the event's name, time, datacontenttype, data, the action's
input, and for a sql event subject, the table.
A timer or blob event's id is random. A SQL event's id names its change, so each change has its own. A retried
delivery and a replayed dead letter keep the same id. A handler can receive an event more than once, since an
attempt counted as failed may still have done its work: make a repeat harmless, for example by recording each handled
id.
Handle a delivery that fails
A delivery that fails, such as when the Function answers with an error, is retried, 3 attempts by default, then kept
as a dead letter, and its Invocation is Failed.
funcdctl eventing dlq lists, describes, replays or discards
dead letters.
To see one, stop any running example, and replace examples/log-burst/ticker.yaml with this manifest, whose input the
contract refuses:
apiVersion: funcd.io/v1alpha1
kind: EventSource
metadata:
name: ticker
namespace: default
resourceGroup: rg1
spec:
timer:
events:
- name: tick
interval: 10s
---
apiVersion: funcd.io/v1alpha1
kind: Sensor
metadata:
name: burst-on-tick
namespace: default
resourceGroup: rg1
spec:
on:
- name: tick
source: ticker
event: tick
do:
- name: burst
on: tick
function: log-burst
input:
items: manyStart the example:
$ funcdctl dev examples/log-burst --cport 8081The first tick fails. In another terminal, list the dead letters until one appears. In TypeScript:
$ funcdctl --server http://127.0.0.1:8081 --token funcd-dev-token eventing dlq list
01M7B1JTZ6P6WHF86MT0JFKYJV burst-on-tick ticker/tick action=burst attempts=3 reason=sensor: function default/log-burst returned status 422: {"error":"event data does not match the input contract","details":[{"path":"/items","message":"got string, want number"}]}In Python, the reason reads additional properties 'items' not allowed. A dead letter keeps the event, not the input
built from it.
A replay delivers a dead letter once, through the Sensor as it is now. Restore the first manifest in ticker.yaml, and
wait until the Sensor's action has no input:
$ funcdctl --server http://127.0.0.1:8081 --token funcd-dev-token get sensor burst-on-tick -n default -o jsonThen replay the dead letter:
$ funcdctl --server http://127.0.0.1:8081 --token funcd-dev-token eventing dlq replay 01M7B1JTZ6P6WHF86MT0JFKYJV
replayed 01M7B1JTZ6P6WHF86MT0JFKYJV (delivered; entry removed)A replay records its own Invocation. When it fails, funcd keeps the dead letter, its attempts set back to 0, and the
command fails with delivery failed (entry re-parked). discard deletes a dead letter without delivering it.
Limits and quotas
- funcd attempts each delivery
eventing.deliveryAttemptstimes, 3 by default, waitingeventing.deliveryBackoffInitial, 100 milliseconds by default, then twice as long each time, up toeventing.deliveryBackoffMax, by default the larger of 10 seconds andeventing.deliveryBackoffInitial. - An attempt waits up to
invoke.activationTimeout, 30 seconds by default, for a worker, then up to 30 seconds for the answer. - At most
eventing.maxDeliveriesInFlightattempts run at once, 32 by default, andeventing.maxInFlightPerTargetper Function or Workflow, 4 by default, so a slow target holds only its own share. - A Sensor holds at most
eventing.maxQueuedPerSensordeliveries, 4096 by default; past that, a delivery becomes a dead letter at once, with a reason that containsdelivery queue of sensor <namespace>/<name> is full. - funcd keeps a dead letter for
eventing.deadletter.retention, 720 hours by default, and at mosteventing.deadletter.maxEntriesper namespace, 1000 by default; an hourly sweep deletes the rest, oldest first.
Data storage
funcd keeps no event except a dead letter's: an event that no Sensor subscribes to is lost. A delivery waits in memory
until its action ends. At shutdown, funcd keeps each waiting delivery as a dead letter, with a reason that contains
daemon shut down with the delivery still queued, for up to server.shutdownTimeout, 15 seconds by default; the rest
are dropped and counted in the log. A crash loses them.
The dead letters, the keys that blob events have fired for and each change feed's position live in the event store,
<storage.dataDir>/eventstore by default, and survive a restart; with storage.mode: memory, they are lost at stop.
Invocations are kept with funcd's other objects, and no sweep removes them.
Status
funcdctl get eventsource <name> -n <namespace> -o json and funcdctl get sensor <name> -n <namespace> -o json print
the phase and the Ready condition; with funcdctl dev, add the first example's --server and --token flags.
| Phase or condition | Reason | Meaning |
|---|---|---|
Timer EventSource Ready | funcd has registered its events. | |
Blob or sql EventSource Ready | Watching | Its Bucket or its SQLDatabase exists, and funcd watches it. |
Blob or sql EventSource Pending | BucketNotFound or DatabaseNotFound | Its Bucket or its SQLDatabase does not exist, and it watches nothing. funcd checks again every eventing.bucketRecheckInterval, 15 seconds by default. |
Blob EventSource SeenListSaved condition False | SaveFailed | funcd cannot save the keys that one of its events has fired for. The message names each such event. |
Sensor Ready | Bound | The Sensor has subscribed to its events. |
Sensor Pending | InvalidInput | The input of an action is not valid, as Shape the input of an action explains, and the Sensor subscribes to nothing. The message names the action and the field, such as action "burst" field "file": expr.check: unknown field "nope" under "event" (position 1) for ${{ event.nope }}. |
Sensor Pending | TargetServesHTTP | An action names a Function whose protocol is http, which only funcd's edge, the part of funcd that receives the calls from outside funcd, calls. The Sensor stays subscribed, and each event of that action ends as a dead letter. |
Invocation Ready | The action ended without an error. | |
Invocation Failed | The delivery ended as a dead letter: after its attempts, or at once when the retry queue refused it. The Invocation's error holds the reason, as the dead letter does. | |
| Any other reason | The message of the Ready condition gives the cause. |
Changes and deletion
- A changed EventSource takes effect at once. A timer event with an unchanged schedule keeps its times, and a new or
changed
cronfirst fires at its next time. A blob event with a newprefixfires for the objects already there. - Deleting an EventSource stops its events and forgets its blob keys; its Sensors stay and receive nothing more.
- A changed Sensor applies to the next event. A waiting delivery whose action changed becomes a dead letter at once,
with a reason that contains
sensor <namespace>/<name> changed with the delivery still queued; replay sends it to the current spec, and one in flight is not attempted again. Deleting a Sensor does the same for all its deliveries; replaying its dead letters then fails. - Under
funcdctl dev, deleting a file deletes its EventSource or Sensor.
CLI errors
funcdctl dev stops before it serves the first example when it meets one of these local setup errors:
| Error | Action |
|---|---|
no node interpreter found for the node handler | Put Node.js on the PATH, or set FUNCD_NODE to the path of node. |
no python interpreter found for the python handler | Put Python 3.12 or later on the PATH as python3, or set FUNCD_PYTHON to its path. |
cannot load the runtime shim (needs Python ≥3.12; set FUNCD_PYTHON) | Put Python 3.12 or later on the PATH as python3, or set FUNCD_PYTHON to its path. |
Run it locally
funcdctl dev differs from a server:
- It lists blob prefixes every second, or at
dev.platform.eventing.blobPollIntervalinfuncdctl.config.yaml. - It applies EventSources and Sensors after the Functions and Workflows, applies a saved change within about a
second, and gives the resource group
devto an object that names none; a server needsmetadata.resourceGroup. - It keeps the event store in memory, even with
--persist, which keeps only its other state, in.funcd-dev.
Examples
- log-burst in TypeScript and in Python: the Function of the first example.
- s3-roundtrip in TypeScript: a Workflow run for each new object.
- sql-orders in Python: a Function called with each change of a table.