File: using-query-command.rst

package info (click to toggle)
ecflow 5.15.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 51,868 kB
  • sloc: cpp: 269,341; python: 22,756; sh: 3,609; perl: 770; xml: 333; f90: 204; ansic: 141; makefile: 70
file content (147 lines) | stat: -rw-r--r-- 4,760 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
.. index::
   single: query state (tutorial)

.. _tutorial-query_state:

Using query command
===================

The :term:`ecflow_client` command :code:`--query` can be used to determine the current value of several characteristics (e.g. node state, node default state, event, meter, variable, trigger).
The same capability is provided by the :ref:`python_api`.

The general format of the :term:`ecflow_client` command :code:`--query` is as follows:

.. code-block:: shell
    :caption: query command

    ecflow_client --query arg1 arg2 arg3

Where:

* arg1 = [ state | event | meter | label | variable | trigger | limit | limit_max | ... ]
* arg2 = <path> | <path>:name     where name is name of a event, meter,limit or variable
* arg3 = trigger expression (optional)  | prev | next    # prev,next only used when arg1 is repeat

Some examples using the query command:

.. code-block:: shell
    
    # return node state 
    state=$(ecflow_client --query state /path/to/node)

    # state that can includes suspended
    dstate=$(ecflow_client --query dstate /path/to/node) 
    
    # return the current value as a string
    value=$(ecflow_client --query repeat /path/to/node )

    # return the previous value as a string, does not modify real repeat
    value=$(ecflow_client --query repeat /path/to/node   prev ) 

    # return the next value as a string, does not modify real repeat
    value=$(ecflow_client --query repeat /path/to/node   next) 

    # return set | clear to standard out
    event=$(ecflow_client --query event /path/to/task/with/event:event_name) 
    
    # returns the current value of the meter 
    meter=$(ecflow_client --query meter /path/to/task/with/meter:meter_name) 
    
    # returns the variable value
    value=$(ecflow_client --query variable /path/to/task/with/var:var_name)   
    
    # returns the current value of the limit 
    limit_value=$(ecflow_client --query limit  /path/to/task/with/limit:limit_name) 
    
    # returns the max value of the limit 
    limit_max=$(ecflow_client --query limit_max /path/to/task/with/limit:limit_name)
    
    # returns the current value of the label 
    label_value=$(ecflow_client --query label %ECF_NAME%:label_name) 
    
    # return true if expression evaluates false otherwise
    value=$(ecflow_client --query trigger /path/to/node/with/trigger \"/suite/task == complete\") 

Update Task Script
------------------

Create a :term:`task script <ecf script>` for a new :term:`task` named :code:`query`, as follows:

.. code-block:: shell
    :caption: $HOME/course/f1/query.ecf
        
    %include <head.h>
    
    meter=$(ecflow_client --query meter /test/f1/t1:progress)
    while [[ $meter -lt 100 ]]
    do
        sleep 2
        meter=$(ecflow_client --query meter /test/f1/t1:progress)
        eventa=$(ecflow_client --query event /test/f1/t2:a)
        eventb=$(ecflow_client --query event /test/f1/t2:b)
        t5_state=$(ecflow_client --query state /test/f1/t5)
        ecflow_client --label=query "meter($meter) eventa($eventa) eventb($eventb) t5_state($t5_state)"
    done
    
    %include <tail.h>

Update Suite Definition
-----------------------

Modify the :term:`suite definition` to add a new task :code:`query` to the family :code:`f1` as follows:

.. tabs::

    .. tab:: Text

        .. code-block:: shell

            # Definition of the suite test.
            suite test
                edit ECF_INCLUDE "{{HOME}}/course" # replace '{{HOME}}' appropriately
                edit ECF_HOME    "{{HOME}}/course"
                family f1
                    edit SLEEP 20

                    [... previously defined tasks omitted ...]

                    task query
                        label query ""
                endfamily
            endsuite

    .. tab:: Python

        .. literalinclude:: src/query-state.py
           :language: python
           :caption: $HOME/course/test.py

**What to do**

#. Add the new task script :file:`query.ecf`, as shown above.
#. Modify suite definition to add a new task :code:`query` to the family :code:`f1`, as shown above.
#. Replace the :term:`suite`, using:

   .. tabs::

      .. tab:: Text

         .. code-block:: shell

            ecflow_client --suspend /test
            ecflow_client --replace /test test.def

      .. tab:: Python

         .. code-block:: shell

            python3 test.py
            python3 client.py

#. Observe the tasks in :term:`ecflow_ui`
#. Modify the task script to query variable :code:`SLEEP`, and add this variable to the query label.

.. note::

    Although a variable can be made accessible in the script by using :code:`%VAR%`, using the query command
    allows to dynamically access the current value or a value from a different server.