I'm trying to loop over an array of data and calling A Rest endpoint for each item in this array, using a serverless-workflow script running on Kogito & Quarkus.
I've modified the following project getting-started-with-serverless-workflow to include a foreach state that calls the Rest endpoint. The resulting workflow is:
{
"id": "greeting",
"version": "1.0",
"specVersion": "0.8",
"name": "Greeting workflow",
"description": "JSON based greeting workflow",
"start": "Loop",
"functions": [
{
"name": "getGreetingFunction",
"operation": "openapi.yml#getGreeting"
}
],
"states": [
{
"name": "Loop",
"type": "foreach",
"inputCollection": ".languages",
"iterationParam": "item",
"outputCollection": ".greetings",
"actions": [
{
"name": "getGreeting",
"functionRef": {
"refName": "getGreetingFunction",
"arguments": {
"name": "${ .name }",
"language": "${ .item }"
}
}
}
],
"end": true
}
]
}
I'm calling this workflow with the following command :
curl -X POST -H 'Content-Type:application/json' -H 'Accept:application/json' -d '{"workflowdata" : {"name": "Helber", "language": ["Spanish","English"]}}' http://localhost:8080/greeting
There are two things that are not working and I don't understand why they aren't, based on the serverless-workflow specification:
"${ .item }" is always null ( same with the syntax ".item" ), which of course generates errors as an output
When replacing "${ .item }" with a fixed value, the output is this:
{ "id": "a20dfd1d-d6bd-41c6-b45f-be1ed9eb962c", "workflowdata": { "name": "Helber", "language": [ "Spanish", "English", "Spanish" ], "greeting": "Greetings from Serverless Workflow, Helber!", "greetings": [] } }
Why isn't the outputCollection of the foreach state .greetings, populated with the results from the two calls ?
Edit: I should have added that those messages always show up when executing the workflow:
2022-09-02 17:15:55,227 WARN [org.kog.wor.res.RestWorkItemHandler] (executor-thread-0) Cannot find definition for variable Loop_5
2022-09-02 17:15:55,296 ERROR [org.jbp.wor.ins.imp.NodeInstanceImpl] (executor-thread-0) Could not find variable Loop_5
2022-09-02 17:15:55,296 ERROR [org.jbp.wor.ins.imp.NodeInstanceImpl] (executor-thread-0) Using process-level scope
2022-09-02 17:15:55,298 INFO [org.kie.kog.exp.jq.JqExpressionHandler] (executor-thread-0) Using default scope
Thanks for your help !
This is bug. It will be corrected with https://github.com/kiegroup/kogito-runtimes/pull/2465