palbaseDocs

Palbase Machines · API

POST/machines/{name}/tasks

Put a task on a machine's queue

Puts a task of one of the machine's task types (its app's @Task classes, as its running version declares them) on its queue, due now, after a delay or at a time — 30 days ahead at most. The platform calls the machine's program for it when it is due — POST /_palbase/tasks/<task> on the machine's own port, with {"task","id","attempt","payload","created_at"}, signed as a cron's call is — waking the machine for it; a 2xx is the task done, 422 is the program saying it can never be done (it fails, with no attempt more), anything else — or no answer within its timeout — an attempt that failed, made again after 10 s, 20 s, … an hour at most, as often as its type's retries allow. A task is delivered at least once: its id is the same through its attempts. A key puts it once: another under the same key, while the first is held (until a day after it is over), answers 200 with the first. 404 when the machine's running version has no task of that name; 413 when the payload is over 64 KiB; 429 when the project's machine time for the period is used up (quota_exceeded) or its queues hold 100,000 tasks not yet done or 256 MiB of what the tasks kept carry (queue_full). The payload is kept as the bytes it was given, and sent to the machine as they are.

Called by your server, with the project's secret key.

Path

namestring · requiredThe machine's name: lowercase letters, digits and dashes, starting with a letter and not ending with a dash, 32 at most.

Request body

taskstring · requiredThe task type: one the machine's running version declares.
payloadany · optionalWhat it carries (any JSON value, 64 KiB at most, with no NUL in its strings): name what it works on, and read it where it runs.
delayinteger · optionalDue this many seconds from now (30 days at most). Not with run_at.
run_atstring (date-time) · optionalDue at this time (30 days from now at most; a time past is now). Not with delay.
keystring · optionalPut once under this key: another task of its type under the same key, while the first is held (until a day after it is over), is not put — the answer is the first.
curl
curl -X POST "https://<your-ref>.palbase.studio/machines/<name>/tasks" \
  -H "apikey: $PALBASE_SECRET_KEY" \
  -H "content-type: application/json" \
  -d '{"task":"string"}'

Responses

200The task put already under its key (held until a day after it is over): nothing new is put

201The task, put on the queue

400Validation failed or a required field is missing

401Missing or invalid API key

403Not the project's secret key

404The project has no machine of this name

429Over the project's request limit, or its machine time for this period is used up

503Temporarily unavailable; retrying is safe after Retry-After

defaultAn error: the envelope names it (`error`) and explains it (`error_description`).

Operation EnqueueTask of machines's contract.