Issue while calling first task in workflow in stackstorm v3.1.0

Hi Can we handle timeout action within the workflow by rerunning timeout action by calling action with the attribute “do” in st2 v3.1.0.
I am using below code

version: 1.0
vars:
  - ActionReTry: 0
  - MaxActionReTry: 1
tasks:
  task1:
    action: core.local
    input:
      cmd: ping 127.2.14.34
      timeout: 10
    next:
      - when: <% result().return_code=-9 and ctx(ActionReTry)=0%>
        publish: 
          - data2: "Yes"
          - ActioncountStr: "{% set count = ctx('ActionReTry')+1 %}{{count}}"
          - ActionReTry: "{{ ctx('ActioncountStr') | int }}"
        do: 
          - task1
      - when: <% result().return_code=-9 and ctx(ActionReTry) = ctx(MaxActionReTry) %>
        publish:
          - data2: "Reached Max and timedout"
        do: 
          - task3
  task3:
    action: core.echo
    input:
      message: 'stop'

In this case it is not taking task1 to run when the condition satisfied.
the same logic is working if I add a another action before task1 and make the present task1 as task2 it is working for rerunning the action when action get timeout i.e by using attribute “do” I am able to run from task2 but can’t able to run as task1 don’t know why that is happening. May I know why is that behaviour?

Thanks in advance

@Balaji.p.s Orquesta supports task retry since v3.2.0. Orquesta Workflow Definition — StackStorm 3.2.0 documentation has an example as well.

@Sheshagiri if we want to use retry option in code it will possible from v3.2.0, but my issue is When I am calling the task1 with do attribute based on variable comparision in when condition it is not executing through a error like no task to execute. Can’t we call task1 with do attribute ?
It is giving following error in logs file when I was running the above code and keep the workflow in running status.

2020-07-07 17:19:34,427 140497650797296 INFO workflows [-] [5f04614db55eb7205f2503a4] Processing request for workflow execution.
2020-07-07 17:19:34,449 140497650797296 INFO workflows [-] [5f04614db55eb7205f2503a4] Requesting conductor to start running workflow execution.
2020-07-07 17:19:34,449 140497650797296 INFO workflows [-] [5f04614db55eb7205f2503a4] Identifying next set (0) of tasks for workflow execution in status "running".
2020-07-07 17:19:34,450 140497650797296 INFO workflows [-] [5f04614db55eb7205f2503a4] No tasks identified to execute next.
2020-07-07 17:19:34,450 140497650797296 INFO workflows [-] [5f04614db55eb7205f2503a4] Updating workflow execution from status "requested" to "running".

@Balaji.p.s I haven’t tried this but I don’t think a task can call itself(i.e it has to transition to another task). The example you cited looks like an ideal fit for retry but as you said that’s only available in 3.2.0.

That said I think if a cyclic loop is detected then it should at least throw an error. Probably worth creating an issue on orquesta.

I tried that a task can call itself. If we add simple echo task before task1 and call task2 in that case it is working fine, but when we are calling intial task then only it is giving error as above.
So we can call any tasks except task1 ? as it is throwing the error while we are calling task1 only.
Thanks

to be clear what you are saying is task1 can call task1. something along the lines of

---
    version: '1.0'
    tasks:
      task1:
        action: core.http url='<URL>'
        next:
          - when: <% succeeded() %>
            publish:
              - http_response: <% result().body %>
          - do: task1

Yes @Sheshagiri. That’s the clarification I need is this possible to call task1 or not ?

I did some digging in the source code and found this example


as you rightly mentioned looks like the first task cannot call itself, my theory is because its a root task and doesn’t have a parent associated with it. I could be wrong here.

Based on the above example I put together the following workflow that will print the greeting max_retry number of times.

---
    version: '1.0'
    input:
        - action_retry: 1
        - max_retry: 2
        - greeting: 'hello'
    output:
        - greeting: <% ctx().greeting %>
        - action_retry: <% ctx().action_retry %>
    tasks:
      setup:
        action: core.noop
        next:
            - when: <% succeeded() %>
              do: task1
      task1:
        action: core.echo message=<% ctx().greeting %>
        next:
            - when: <% succeeded() and ctx().action_retry = ctx().max_retry %>
              do: finish
            - when: <% succeeded() and not ctx().action_retry = ctx().max_retry %>
              publish: 
                - action_retry:  <% ctx().action_retry + 1 %>
                - greeting: <% ctx().greeting %>, <% result().stdout %>
              do: task1
      finish:
        action: core.noop

so following is the output

root@2da88f4a3f92:/opt/stackstorm/packs/default# st2 run http.task_recursion
..
id: 5f0603b2c1c83bf95e23e53f
action.ref: http.task_recursion
parameters: None
status: succeeded
start_timestamp: Wed, 08 Jul 2020 17:34:42 UTC
end_timestamp: Wed, 08 Jul 2020 17:34:44 UTC
result:
  output:
    action_retry: 2
    greeting: hello, hello
+--------------------------+------------------------+--------+-----------+------------------------------+
| id                       | status                 | task   | action    | start_timestamp              |
+--------------------------+------------------------+--------+-----------+------------------------------+
| 5f0603b2feda037f18a0693a | succeeded (0s elapsed) | setup  | core.noop | Wed, 08 Jul 2020 17:34:42    |
|                          |                        |        |           | UTC                          |
| 5f0603b2feda037f18a0693d | succeeded (1s elapsed) | task1  | core.echo | Wed, 08 Jul 2020 17:34:42    |
|                          |                        |        |           | UTC                          |
| 5f0603b3feda037f18a06940 | succeeded (0s elapsed) | task1  | core.echo | Wed, 08 Jul 2020 17:34:43    |
|                          |                        |        |           | UTC                          |
| 5f0603b3feda037f18a06943 | succeeded (1s elapsed) | finish | core.noop | Wed, 08 Jul 2020 17:34:43    |
|                          |                        |        |           | UTC                          |
+--------------------------+------------------------+--------+-----------+------------------------------+
root@2da88f4a3f92:/opt/stackstorm/packs/default#

I hope this helps.

Thanks for the information @Sheshagiri. So as per your theory if the task don’t have associated with any parent it won’t be callable right ?
For all the tasks in workflow parent task is task1 ?