dotFactory
Documentation / Build a factory

Triggers

Build a factory

Manual forms, cron schedules, GitHub webhooks and authenticated HTTP deliveries — and how each one seeds a Run.

A trigger is how a Run begins. It declares a kind, an out: interface and optional config; admission supplies those out values as the Run's seed, which is checked for conformance and then held constant for the whole Run.

type Ticket = { key: text, title: text }

trigger start:
  kind: manual
  out: { ticket: Ticket }

A trigger fires once, before the steps. A node that reads the seed runs once; to process another ticket, admit another Run.

Manual

kind: manual is the on-demand path. In the app, the trigger page renders its out: ports as a form (records become field groups), and Fire admits the Run.

Over HTTP, POST /api/runs takes {"trigger": "start", "seed": {...}} and answers 202 with the new Run id. The trigger may also carry a static config: that the adapter reads — a prompt, a path, a default.

Cron

kind: cron fires on a schedule while the scheduler process is polling:

trigger scheduled:
  kind: cron
  config: {
    schedule: "0 */6 * * *"
    schedule_key: "todo_worker.schedule"
  }
  out: { expression: text, scheduled_at: time, fired_at: time }
  • schedule is a standard five-field cron expression.
  • schedule_key, when present, names a configuration value that overrides the expression. That makes the cadence deployment configuration: change the value and the schedule moves without uploading a new factory version.
  • The seed records which tick the Run serves: the expression, when it was due and when it fired, so a late Run is visibly late.

The schedule's next-due instant is stored, not held in a process. Restarting a poller does not lose it; several pollers agree on one successor; a window missed while the process was down coalesces into one fire.

A schedule can be paused and resumed by an owner or admin: on the trigger page, in the factory's trigger row, or beside the factory on the dashboard. Pausing keeps the cursor and stops future fires; resuming arms the next occurrence, skipping the windows missed while paused. Runs already admitted are unaffected.

GitHub

kind: github admits a Run from a verified webhook delivery:

trigger on_commit:
  kind: github
  config: gh::GithubConfig = {
    path:    "/api/github/webhook"
    target:  { one: { repo: "acme/widgets" } }
    actions: ["synchronize", "opened", "reopened"]
  }
  out:
    pr:         gh::PullRequest
    commit:     text
    repository: gh::Repository
    base_ref:   text
  • path is the delivery path under /api/github/; GitHub posts to POST /api/github/<path>.
  • target chooses one repository (one: { repo }) or several (many: { repos: […] }). A delivery for another repository is ignored.
  • actions filters the event actions.
  • out is the seed: fields projected from the payload, conformed before admission.

The delivery is verified with the deployment's webhook secret (or the trigger's config.hmac_secret_key), and every verified delivery is stored raw with its outcome, so a replay cannot admit the same event twice. Push events use the same endpoint and re-check repository-linked factories.

GitHub covers the App, the events and the delivery log.

HTTP

kind: http is the generic form: any sender can deliver to POST /api/hooks/<factory_id>/<trigger>, and the JSON body is the seed.

trigger deploy_done:
  kind: http
  config: { auth: { bearer: { key: "deploy_hook_token" } } }
  out: { environment: text, commit: text }
curl -X POST "$API/api/hooks/$FACTORY_ID/deploy_done" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"environment":"prod","commit":"9e1ec09"}'
  • The endpoint is derived from the factory id and the trigger name; there is no path to configure, so two factories cannot collide.
  • The body's keys are the trigger's out ports. config.body_key selects a nested object first (for a sender that wraps its payload).
  • config.auth is required and is one of two modes: bearer { key } checks Authorization: Bearer <token>, and hmac { key } checks X-Factory-Signature-256: sha256=<hex> over the raw body. key names a secret — set it on the factory's Secrets page. A factory whose secret is missing does not start, so an anonymous caller can never admit a Run.
  • An optional Idempotency-Key header makes a retry the same Run; without it each delivery admits a fresh Run.
  • Statuses: 202 admitted, 401 bad credential, 404 unknown factory or trigger, 422 the body does not conform to the trigger's ports.

Trigger state in the app

The factory page lists each trigger and links to its page:

  • manual — the seed form and the trigger's Run history;
  • cron — expression, server time, next fire, pause/resume and history;
  • github — the endpoint, secret key name, accepted events and history;
  • http — the derived endpoint, auth mode, secret key, body shape and history.

A trigger whose kind the deployment does not implement is still shown, but the factory is not runnable until a deployment with that adapter serves it. The factory page states which kinds are missing; see Adapters.

Your factories

Your factories will appear here. Create one and open it beside this guide.