Before your first deploy
- Set your project’s endpoint to the URL the route will have, like
https://your-app.com/api/nelkap. - Set
NELKAP_API_KEYandNELKAP_SECRETin your host’s environment variables. See Installation. - Deploy. When your app starts,
registerWorkflowssends its list of workflows to Nelkap.
What your endpoint needs
Nelkap calls your endpoint over the internet, from its own servers. The URL must:- Use HTTPS, on a domain name. An IP address or
localhostisn’t accepted. - Be public. A route behind a sign-in, a VPN, or a firewall that blocks Nelkap can’t be reached.
- Answer within 30 seconds, without a redirect.
handleanswers at once, so this only matters if something runs before it.
handle checks your project’s secret instead.
How Nelkap calls your app
Each time a run has work to do, Nelkap sends a POST request to your endpoint:- The
Authorizationheader carries your project’s secret, asBearer <secret>.handleanswers401if it doesn’t matchNELKAP_SECRET. - The JSON body names the workflow, and carries the run’s ID, its payload, and the steps already saved.
handle answers 202 at once, then runs the workflow in the background. While the workflow runs, the SDK saves each step as it finishes, and tells Nelkap every minute that the run is still going.
If your endpoint doesn’t answer with a 2xx status, or can’t be reached, Nelkap tries again about a minute and a half later. After three attempts, the run fails with deliveryFailed. Once your endpoint is back, replay the run.
Register your workflows on every start
registerWorkflows runs each time your app starts, and sends the full list of workflows to Nelkap. The list replaces the one Nelkap had:
- New workflows are added.
- Workflows you changed take their new events, schedule, and concurrency.
- Workflows you removed are turned off, and their runs that haven’t started, or are sleeping or waiting, are canceled.
run and emit make sure the list is sent before their own request, so what you start from your code is never affected. A change that must apply before then, like a new schedule, waits for that first request: start a run or emit an event from the new deploy to send the list right away.
Every instance of your app must register the same list. A project has one endpoint, so all its workflows run in one app: give each app its own project. See Workspaces and projects.
Runs during a deploy
A deploy can stop your app in the middle of a run. Nothing is lost:- Runs that are sleeping, waiting, or waiting for their turn aren’t running anywhere, so the deploy doesn’t touch them.
- A run cut off in the middle of a call stops sending its signal. About five minutes later, Nelkap calls your app again, now on the new version, and the run picks up from its last saved step.
- A step cut off before its result was saved runs again from its start. See When a step can run twice.
Time limits
Nelkap puts no limit on how long a call takes. Your host might. On serverless hosts, a function stops after a set time, and some stop as soon as the response is sent:- Pass your host’s
waitUntiltohandle, so the work goes on after the response. Each framework page shows the right one. - When the host cuts a call off at its limit, the steps already saved are kept, and Nelkap calls your app again about five minutes later to go on from there.
- Keep each step shorter than your host’s limit. A single step longer than the limit can never finish.
Rotate your project’s secret
If your secret leaks, rotate it from your project. Your endpoint then turns every call away until it has the new one, so updateNELKAP_SECRET and deploy right after. Calls in the meantime are tried again, up to three attempts in about three minutes. A run whose three attempts all fail shows deliveryFailed: replay it once the new secret is live.