Kogito job service cron

238 views
Skip to first unread message

Mateusz Grabowski

unread,
Aug 8, 2023, 10:40:12 AM8/8/23
to Kogito development mailing list
Hi i want to use job-service as a cron to schedule to run my proces periodically every day at 12. 
I saw that i can send post to job-service to create jobs - but cannot create cron.
I think i should use v2/jobs  with 
{ "id": "string", "correlationId": "string", "state": "SCHEDULED", "schedule": { "type": "string" }, "retry": { "maxRetries": 3, "delay": 0, "delayUnit": "MILLIS", "maxDuration": 180000, "durationUnit": "MILLIS" }, "recipient": { "type": "string" } }

What i can find in job-servie swagger.. but when i try to execute with such data i receive Error: Bad Request

How can i create such job? (run everyday my kogito process by job-service).

Regards,
Mateusz

Walter Medvedeo

unread,
Aug 10, 2023, 12:45:54 PM8/10/23
to Kogito development mailing list
Hi Mateusz,
yes, we don't have the ability to create cron jobs yet, however,  if you'd like to create the process instance with a periodicity of  24 hours, I think you can try by doing something like this:

1) imagine that the job service is started in  http://localhost:8280

2) Send a POST to the following endpoint: http://localhost:8280/v2/jobs (and yes, you must use v2 API) with the following request:

{
"id": "MY_CRON_JOB",
"correlationId": "MY_CRON_JOB",
"state": null,
"schedule": {
"type": "timer",
"startTime": "2023-08-10T23:59:59.000+02:00",
"repeatCount": 99999,
"delay": 24,
"delayUnit": "HOURS"
},
"retry": null,
"recipient": {
"type": "http",
"method": "POST",
"headers": {
"Content-Type" : "application/json"
},
"queryParams": {},
"payload": {
"type": "json",
"data": {
"workflowdata" : {
"param1": "constantValue1",
"param2": "constantValue2"
}
}
}
}
}

3) explanations about the request

id: is a convenient string that you can use later to cancel the job when you don't need it anymore

correlationId: use the same value as id

repeatCount: indicates the number of times the job execution must be repeated, set a value >= 0     and  < MAX_INTEGER

recipient: basically defines the endpoint that must be invoked. In the example I'm using the endpoint of an example servlerless workflow http://localhost:8380/hello_world. The other contents, like type: "http" and headers you must keep as they are.

payload:
in the example above, I'm simulating the execution of a servlerless workflow, that expects a the following json
"workflowdata" : {
"param1": "constantValue1",
"param2": "constantValue2"
}
(the other vales are part of the content definition)

if you don't need to pass any parameters to you process you can set:

"payload":null

or

"payload": {
"type": "json",
"data": { }
}
}


I hope this helps,

Regards,
Walter.

Mateusz Grabowski

unread,
Aug 11, 2023, 4:31:52 AM8/11/23
to Kogito development mailing list
Hi,

thank you for your response!
It was helpfull coz now i can execute sucessfully /v2/jobs but still is not working correctly.

1. When i put n delayUnit Hours or Seconds or Minutes any time always is displaying as MILLIS:
1.png

2. When i created job with 30000 which is 5 min all my repeats was executed instatly;
2.png

Regards,
Mateusz

Mateusz Grabowski

unread,
Aug 11, 2023, 5:22:21 AM8/11/23
to Kogito development mailing list
Ok i found my problem i was creating with pass startTime so it wans't works fine but when startTime is in future this will start "ok" but still only MILLIS parametrs is possibile 3.png
Reply all
Reply to author
Forward
0 new messages