Validate output and make decision in orquesta

(gmnvn) #1

Hi,

I have an orquesta, I need to check for something in mysql and then make decision if its matching.

Here’s the mysql function:

  check_in_db:
    action: mysql.select connection="manivannang" query="select status from jobs where id = <% ctx(cjaid) %>;"
    next:
     - when: <% succeeded() %>
       publish: msg="Mysql output = <% result().result %>"
       do: post_to_slack

Currently I’m getting a slack message as:
Mysql output = [{u'status': u'exited'}]

Want to evaluated if it is exited , do exit_related_task, if it is running, do running_related_task.

(Lindsay Hill) #2

Look at examples like st2ci/st2_pkg_e2e_test.yaml at master · StackStorm/st2ci · GitHub -that has conditionals based upon variable values.

1 Like
(gmnvn) #3

Thanks a lot. Let me take a look.

(gmnvn) #4

Hi,

From the example I tried this:

  check_in_db:
    action: mysql.select connection="manivannang" query="select status from jobs where id = <% ctx(cjaid) %>;"
    next:
     - when: <% succeeded() and result().result.status = "'finishing'" %>
       publish: msg="Mysql output = <% result().result %>"
       do: post_to_slack

The logic seems to be working, I tested with !=. But the actual comparison is not working, due to the mysql output format. result().result.status is giving [u'finishing'].

Tried using:

<% succeeded() and result().result.status = 'finishing' %>
<% succeeded() and result().result.status = "'finishing'" %>
<% succeeded() and result().result.status = "u'finishing'" %>
<% succeeded() and result().result.status = "[u'finishing']" %>

But none of it working, but when i use <% succeeded() and result().result.status != "'finishing'" %> its going through. Which indicates I’m missing something.

I definitely missing something to access the final value.

EDIT:
I mitigated that with:
<% succeeded() and result().result.status.contains(finishing) %> to validate.

Would be really nice if you can help how can i access the value finishing. The typical json way of accessing (result().result.status[0]) is not working :disappointed:

(Lindsay Hill) #5

What does your result object look like?

(gmnvn) #6

result() object:

{u'stdout': u'', u'exit_code': 0, u'stderr': u'No handlers could be found for logger "st2.st2common.util.loader"\n', u'result': [{u'status': u'finishing'}]}

result().result object:

[{u'status': u'finishing'}]

result().result.status object:

[u'finishing']


EDIT:
For now I found a way to access just the value finishing, instead of [u'finishing'] by using result().result.status.first(), would like to know is there any other better way to do this.

(Lindsay Hill) #7

Haven’t looked too closely, but looks like it should be something like result().result[0].status?

Seems a bit odd that result is an array of dictionaries