# Packages
# README
Sonic
It's a runner!
Sonic plucks jobs from a Kewpie queue and runs their body on the command line. The body of the task should be the string you would type in as you were sitting at the terminal, ie:
{
"body": "echo 'Sonic is rad\!'",
}
It's handy for when you want to drive a workload from a Kewpie task queue, but don't want to integrate the queue consumption library into the language the service is written in.
Running it
You must declare the queue you wish to listen to, the kewpie backend to use, whether to retry failed jobs, and any vars required by your chosen backend. eg:
export DB_URI=postgres://kewpie:wut@localhost:5432/kewpie?sslmode=disable
export KEWPIE_BACKEND=postgres
export QUEUE=lolhai
export RETRY=true
export SINGLE_SHOT=false
export DIE_IF_IDLE=false
export MAX_IDLE=30s
RETRY
controls whether or not a task that failed (exited > 0) will be retried
SINGLE_SHOT
mode tells Sonic to exit its own process after handling its first task and not look for a second one
DIE_IF_IDLE
tells Sonic to exit if it is ever idle for more than MAX_IDLE
MAX_IDLE
is a Go style Duration string. If DIE_IF_IDLE
is not set, this setting has no effect
Using it
Sonic will check the Tags attribute of a Kewpie task for webhooks to call on start, success and error.
{
"body": "echo 'Sonic is rad\!'",
"tags": {
"webhook_start": "http://example.com/telemetry/start",
"webhook_success": "http://example.com/telemetry/success",
"webhook_fail": "http://example.com/telemetry/error",
}
}
If these are present, Sonic will send a POST payload with the contents of the task.
For the start webhook, if the server returns a 400
error code Sonic will abort the task and not requeue it. If the server returns anything in the 2xx
range the task will continue. Any other response will be treated as an error and Sonic will abort this run of the task and requeue it to be retried.
For the success webhook, if the server returns a 400
error code Sonic will abandon the task and not requeue it. If the server returns anything in the 2xx
range the task will be acked and removed from the queue. Any other response will be treated as an error and Sonic will abort this run of the task and requeue it to be retried if the global retry flag is set to true. If the global retry is set to false we assume that the tasks on this queue are non-idempotent and we should not retry.