[note] Job Suspend Schedules is schedules that suspend scheduled jobs.
Kuroko2 has a DSL for defining a custom workflow. Here is a basic example:
# This is a single line comment
env: DRY_RUN=1
execute: echo 'Hello'
the execute
task launches specified command. Workflow engine executes next line if it succeeded or stop the workflow if it failed.
For more information, see tasks.md and Defining Workflow section.
Doing tasks by sequencial.
my_project_runner: MyProject::Task1.run
my_project_runner: MyProject::Task2.run
when error occurs, the job stops and we can choose Cancel or Skip or Retry.
Action | Description |
---|---|
Cancel | Stop all steps in the job. |
Retry | Execute from failed step. |
Skip | Ignore the failed step and execute from next step. |
Status | Description |
---|---|
WORKING | A job is working. |
ERROR | Your tasks finished with non-zero exit status. |
SUCCESS | Your tasks finished with the zero exit status (final state) |
CANCEL | Press the cancel button or prevent running by kuroko2 system. (final state) |
[note] “ERROR” is not a final state. You should cancel or retry “ERROR” state jobs. If your “ERROR” state job don’t need treat carefully, you may want to add a auto_skip_error
task in your job script.
Kuroko2 notifies job statuses by below methods.
You can configurable notifications frequency.
If you enable this option, Kuroko2 notifies all events by Slack/Hipchat/Webhook (except Email) that jobs state is changed, Events is below.
If you disable this option, Kuroko2 notifies only the error or critical situation.
If you enable this option, Kuroko2 notifies messages that the scheduled job prevented by Kuroko2 in accordance with the “Next Job Execution” options.
Kuroko2 includes additional HTTP headers with webhook POST request.
Request header | description |
---|---|
X-Kuroko2-Id | Unique ID for the event. |
X-Kuroko2-Signature | HMAC hex digest using secret_token (if configured) |
POST /webhook_endpoint_you_configured HTTP/1.1
Host: localhost:4567
X-Kuroko2-Id: dd03409e-135c-4de4-8bcb-b6ca09c64624
X-Kuroko2-Signature: sha256=48969b34a3d9979d83a9a13b74d20575b03a12f16e7071e3db2148fe182c8b7e
User-Agent: Kuroko2-Webhook
Content-Type: application/json
Content-Length: 537
{
"action":"notify_finished",
"level":"SUCCESS",
"subject":"Finished to execute 'Test Job1'",
"message":null,
"job_instance":{
"url":"http://localhost/definitions/1/instances/100",
"id":4472,
"script":"noop:\r\n",
"finished_at":"2016-11-10T15:39:10+09:00",
"canceled_at":null,
"error_at":null,
"created_at":"2016-11-10T15:38:38+09:00"
},
"job_definition":{
"url":"http://localhost/definitions/1",
"id":128,
"name":"noop job1",
"description":"noop"
}
}
A job can be executed by the execution API.
The execution API requires basic authentication. Set the api_basic_authentication_applications
key in kuroko2.yml if you enable the API.
To execute job from API, check Allow API execution of this job
in job definition.
curl -H "Content-type: application/json" -H "Accept: application/json" -H "Authorization: Basic dGVzdF9jbGllbnRfbmFtZTpzZWNyZXRfa2V5\n" -XPOST -d http://localhost:5000/v1/definitions/2/instances
POST /v1/definitions/2/instances HTTP/1.1
Host: localhost:5000
User-Agent: curl/7.52.1
Content-type: application/json
Accept: application/json
Authorization: Basic dGVzdF9jbGllbnRfbmFtZTpzZWNyZXRfa2V5\n
HTTP/1.1 201 Created
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
X-Content-Type-Options: nosniff
Content-Type: application/json; charset=utf-8
ETag: W/"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
Cache-Control: max-age=0, private, must-revalidate
X-Request-Id: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
X-Runtime: 0.098753
Transfer-Encoding: chunked
Curl_http_done: called premature == 0
Connection #0 to host localhost left intact
{"id":10,"status":"working"}
To verify a webhook request, compare that to the value of the X-Kuroko2-Signature header.
Ruby and Sinatra example is below.
require 'openssl'
post '/' do
body = request.body.read
if valid_signature?(body)
'ok'
else
'ng'
end
end
def valid_signature?(body)
algorithm, signature = request.env['HTTP_X_KUROKO2_SIGNATURE'].split('=')
Rack::Utils.secure_compare(signature, OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new(algorithm), ENV['KUROKO2_SECRET_TOKEN'], body))
end
Environment variable | ex. |
---|---|
KUROKO2_JOB_DEFINITION_ID | “137” |
KUROKO2_JOB_DEFINITION_NAME | “My daily job sample” |
KUROKO2_LAUNCHED_TIME | “2016-04-20T16:29:57.302+09:00” |
KUROKO2_JOB_INSTANCE_ID | “100” |
TODO