Skip to Content
Overview

Loops docs

Screenshot of successful loop run

What is a loop?

A loop (a Health Loop) is your workflow. In short:

  • Instructions — what the loop should do (your code).
  • Triggers — what starts a run; the platform calls run on your class.
  • Connectors — calls out to other systems (integrations, HTTP, and similar).
  • Outputs — what each run produces or sends outward.
  • Event log — what fired, what was called, what came back, and what failed—available to read later.

The snippet below maps the same pieces to code (// comments show which is which).

export class HealthLoop extends Loop { async run(event: HealthEvent, step: HealthStep) { // Trigger — input for this run (payload from API, schedule, …) const { patientId, phoneNumber } = event.body; // Instructions — named `step.do` calls and waits, in order await step.do("Generate a health scan", async ({ ctx }) => { // Connector — built-in integration (FACIAL_SCAN) await ctx.FACIAL_SCAN.create({ expiresIn: 3600, // 1 hour metadata: { patientId, phoneNumber }, }); }); // `waitForScan` suspends the run until the scan finishes (or times out), // then returns the results — no separate read step needed. const scan = await step.waitForScan({ timeout: "30 minutes" }); await step.do("Send a notification", async () => { // Connector + output — your HTTP call; this is the outward result await fetch("https://api.example.com/send-notification", { method: "POST", body: JSON.stringify({ patientId, phoneNumber, scanResult: scan, }), }); }); // Event log — steps and `console` are recorded for you (nothing extra to add) } }

Loop code is versioned when you deploy; each run carries its own steps, connector traces, and log lines.

Last updated on