Skip to content

Keep a run’s claim on its import

POST
/orgs/{org}/imports/{id}/runs/{run}/heartbeat
curl --request POST \
--url https://api.sloose.com/orgs/org_9f3c/imports/imp_4d1a/runs/run_7c2e/heartbeat \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{ "leaving": true }'

The client that authorised the run renews its claim every thirty seconds, on a two-minute lease — a dry run and a run paused on an error too, since neither writes. A run that is writing renews it too: a write, or a report of the rows it settled, renews the lease once that is 20 seconds old, so a window whose timers run slowly (a tab in the background gets a repeating timer once a minute) keeps a run that is writing; a lapsed lease is still lost, never revived. A lease that ran out is lost, not revived: the import may have been released and changed since, and the answer is 409 LEASE_LOST. Only the session or token that authorised the run may renew it.

A run stopped at its row limit (over_limit) is renewed too, while it finishes the rows it had already counted (#1857): its stop released the import, so it is renewed while nobody else holds it, and its status stays over_limit — the renewal keeps the rows it counted writable, never the run going. Its done ends the lease.

With leaving: true the client says it is going — its page closed with the run going — and the claim is cut to five seconds instead: time for what it sent as it went (its last counts and settled rows) to land, after which the server ends the run abandoned, counted from its records, as it would have two minutes later. From then on the claim only shortens: an ordinary heartbeat landing after it keeps the cut.

org
required

The organisation id the session was issued for. A token for one organisation can never read another.

string
Example
org_9f3c

The organisation id the session was issued for. A token for one organisation can never read another.

id
required

The import id.

string
Example
imp_4d1a

The import id.

run
required

The run id, from POST /entitlements/runs/authorise.

string
Example
run_7c2e

The run id, from POST /entitlements/runs/authorise.

Media typeapplication/json
object
leaving

The client is going (#1649): cut the claim to a few seconds rather than renew it. Anything but true is an ordinary renewal.

boolean | null
key
additional properties
Examplegenerated
{
"leaving": true
}

Renewed.

Media typeapplication/json
object
leaseExpiresAt
required

When the claim lapses now.

string
Examplegenerated
{
"leaseExpiresAt": "example"
}

No bearer, or one that no longer resolves: a session that is unknown or expired (code: AUTH_REQUIRED), or an API token that was revoked or expired (TOKEN_REVOKED, TOKEN_EXPIRED), whose organisation is gone (ORG_NOT_FOUND) or whose member or user row is (MEMBERSHIP_GONE).

Media typeapplication/json

The error envelope every non-2xx answer uses.

object
error
required

Human-readable explanation.

string
code

Machine-readable reason. Absent on a few legacy 400s.

string
key
additional properties
Examplegenerated
{
"error": "example",
"code": "example"
}

Not the session or token that authorised this run (code: NOT_YOUR_RUN), or the role is too low. Like every route behind a session: a session signed in but in no organisation is refused code: NO_ORG, a banned person code: BANNED, and a closed organisation code: ORG_CLOSED.

Media typeapplication/json

The error envelope every non-2xx answer uses.

object
error
required

Human-readable explanation.

string
code

Machine-readable reason. Absent on a few legacy 400s.

string
key
additional properties
Examplegenerated
{
"error": "example",
"code": "example"
}

No such import or run, or it is not visible to this session.

Media typeapplication/json

The error envelope every non-2xx answer uses.

object
error
required

Human-readable explanation.

string
code

Machine-readable reason. Absent on a few legacy 400s.

string
key
additional properties
Examplegenerated
{
"error": "example",
"code": "example"
}

The lease ran out and the import was released (code: LEASE_LOST).

Media typeapplication/json

The error envelope every non-2xx answer uses.

object
error
required

Human-readable explanation.

string
code

Machine-readable reason. Absent on a few legacy 400s.

string
key
additional properties
Examplegenerated
{
"error": "example",
"code": "example"
}

The restore switch is on (code: MAINTENANCE): every route but /health and /robots.txt is refused before anything is read, except the operator’s own POST /staff/people/{id}/delete with the ADMIN_TOKEN. Sloose is down for maintenance. Please try again in a few minutes.

Media typeapplication/json
object
error
required
string
code
required
string
Allowed value: MAINTENANCE
Example
{
"code": "MAINTENANCE"
}
Retry-After
integer

Seconds until asking again is worth it (300 while the switch is on).

Report a problem with this page

sloose.com