-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Accessing DO_WHILE 'iteration' value inside the the looped tasks. #1677
Comments
Hi @krishnaputhran ,
|
Hi @manan164 thank you very much for the response and I appreciate your timely response. I have tried reading the do-while-task documentation, but couldn't get answer for my problem, but somehow I didn't consider the use fo LAMDA tasks. WorkfFlow Definition{ Input to the workflow{ Even the Conductor UI shows the execution of LAMDA function only once, although my input array products size is 2. But in the DO-WHILE task output shows two executions but same output from the LAMDA task. If LAMDA executed properly, I would have see pluCode: 4904230037873 also. DO-WHILE task output from the conductor UI{ If I add a normal task, like HTTP, after the LAMDA task it gets executed twice and in the conductor UI as the screen shot pasted above, I could see two rows of it after the LAMDA task. I removed it here for reducing the text size. |
@manan164 I could see this is a defect. By adding a dummy task before this one makes the next task to be executed. So issue is that, in a DO_WHILE loop, the first task in the loopOver is gets executed only once. So a dummy task need to be added to address this issue. But one more issue I saw. Hope you reply to my concern. As per your sample code, I tried to access the array values inside the loop, but it always gives the 0th array value. "iterator": "$.test_loopTask['iteration']", from the above script expression, the value returned is always the zeroth value from the orders. |
Hi @krishnaputhran There may be an issue with the sequence number. Please check do_while task output there you will see all loopOvertaks output. |
@manan164 thanks for the response. The do_while task output i have checked, and its has the expected output. Only issue is getting the "iteration" value in subsequent iterations.
to my surprise, this worked, but had some strange issue. During the execution the value of iterator fetched using "${test_loopTask.output.iteration}" goes like this If there are only two iterations, the iterator will always have the value 1. meaning for the second execution the value of iteration will still be 1 and after second execution the iteration value starts increasing. But I am afraid, as per my reading on DYNAMIC_FORK will solve my problem. My issue is I want to fetch the array value one by one, which forms input to my set of tasks to be executed in sequence. This is a typical looping use-case. My task execution list is not dynamic. Anyway I'll give a try. |
@krishnaputhran |
@manan164 Can you please chime in on this one? Thanks |
Sure. @apanicker-nflx |
Any update on this issue? This proposed solution does not work, and yields the first element of the array for every iteration. |
There seems to be an error in the workflow task (
|
I tried that. It doesn't work either. iterator becomes null, and script still returns the 0 element in the array.
|
Better not use workflow.input as it is immutable (or at least suppose to be) I found out that {
"schemaVersion": 2,
"name": "test_do_while_workflow",
"description": "test_do_while_workflow",
"tasks": [
{
"name": "mock_data",
"taskReferenceName": "mock_data",
"inputParameters": {
"scriptExpression": "var products = new java.util.ArrayList();\nproducts.add({\"pluCode\": 4900001157498,\"quantity\": 2});\nproducts.add({\"pluCode\": 4904230037873,\"quantity\": 3});\nreturn {\"products\": products};"
},
"type": "LAMBDA"
},
{
"name": "test_loopTask",
"taskReferenceName": "test_loopTask",
"inputParameters": {
"orders_count": 2
},
"type": "DO_WHILE",
"loopCondition": "$.test_loopTask['iteration'] < $.orders_count",
"loopOver": [
{
"name": "get_order_at_index",
"taskReferenceName": "get_order_at_index",
"inputParameters": {
"orders": "${mock_data.output.result.products}",
"iterator": "${test_loopTask.output.iteration}",
"scriptExpression": "return $.orders.get($.iterator);"
},
"type": "LAMBDA"
}
]
}
],
"ownerEmail": "test@example.com",
"version": 1,
"outputParameters": {
"result": "${test_loopTask.output}"
}
} Returns the following output: {
"result": {
"1": {
"get_order_at_index": {
"result": {
"pluCode": 4900001157498,
"quantity": 2
}
}
},
"2": {
"get_order_at_index": {
"result": {
"pluCode": 4904230037873,
"quantity": 3
}
}
},
"iteration": 2
}
} |
Interesting.. I did try output.iteration, but I found, as reported here by others, that the output.iteration sequences as "1,1,2,3,4" instead of "0,1,2,3,4", which is not usable. perhaps this has been fixed lately? This would def. be preferred to my hack. We are running our own instance of conductor.. perhaps it is old.. |
Hi @FrankOwen The seq number issue has been fixed via 1815. |
Thanks, @manan164 . I guess our deployment must be more than 17 days old! I will see about getting updated. Would be good to remove my hack. Putting it in output is a little weird, since I think of 'output' as FINAL value of a task. But I'll take whatever works! |
@manan164 I confirmed we are at 2.27.2, which does not have 1815 fix. Does that also fix the issue where first task only executes once? I'm using a dummy task as workaround. |
This issue is stale, because it has been open for 45 days with no activity. Remove the stale label or comment, or this will be closed in 7 days. |
This issue was closed, because it has been stalled for 7 days with no activity. |
@apanicker-nflx @manan164 - Why do you say, do not use within loopover task? |
LoopTaskIterationWFDefinitionwithRun.pdf |
@krishnaputhran @manan164 @FrankOwen
Does the above work to interpolate array size in task input? |
Hi, I am trying to execute a task 'A' inside do while task and I want to change the input to task 'A' on every iteration. Can we do this? |
Hi @Priyank0711 , Yes it is possible. Please check @elisherer 's comment, #1677 (comment) |
…e DoWhile.execute method. The DO_WHILE TaskModel is persisted before the loop-over tasks are created. Therefore, the loop-over tasks will have access the iteration field in DO_WHILE TaskModel.
… created in th… (#45) * Add an ack request for each task polled from queue, when polling in batches * fixed typos * remove manual acking in tests, since this done by default * Fix for Netflix#1677, inspired from Netflix#2881. Loop-over tasks are created in the DoWhile.execute method. The DO_WHILE TaskModel is persisted before the loop-over tasks are created. Therefore, the loop-over tasks will have access the iteration field in DO_WHILE TaskModel. Co-authored-by: gardusig <gustavo.gardusi@gmail.com> Co-authored-by: Anoop Panicker <34087882+apanicker-nflx@users.noreply.github.com> Co-authored-by: Amol Katdare <amol.katdare@gmail.com> Co-authored-by: Anoop Panicker <apanicker@netflix.com> Co-authored-by: Aravindan Ramkumar <1028385+aravindanr@users.noreply.github.com>
…e DoWhile.execute method. The DO_WHILE TaskModel is persisted before the loop-over tasks are created. Therefore, the loop-over tasks will have access the iteration field in DO_WHILE TaskModel.
Hi, anyone know how to access the iterator value inside the tasks, which are running as part of the DO_WHILE loop. For eg: I want to read an array value inside the running tasks. The array would be an input to the looped task from another task output, which was executed before the loop started. I am not sure how we can use the DO_WHILE 'iteration' variable for reading the array values.
I want to use the 'iteration' value something like below inside a task defined inside the DO_WHILE loop. Here 'preOrder_service' is task which runs before the the loop starts and 'products' is an array.
preOrder_service_get.output.response.body..products['iteration'].pluCode
The text was updated successfully, but these errors were encountered: