<div class="section" id="add-an-event">
<span id="add-event"></span><span id="index-0"></span>
<div class="line-block">
<div class="line">Sometimes waiting for the completion of a task is not good enough.</div>
<div class="line">If a task is producing several results, another task may start as</div>
<div class="line">soon as the first results are ready.</div>
<div class="line">For that, ecFlow introduces the concept of <a class="reference internal" href="/wiki/display/ECFLOW/Glossary#term-event"><em class="xref std std-term">event</em></a>‘s.</div>
</div>
<div class="line-block">
<div class="line">An <a class="reference internal" href="/wiki/display/ECFLOW/Glossary#term-event"><em class="xref std std-term">event</em></a> is a message that a task will report to <a class="reference internal" href="/wiki/display/ECFLOW/Glossary#term-ecflow-server"><em class="xref std std-term">ecflow_server</em></a> while</div>
<div class="line">it is running.</div>
</div>
<p>Events have names and a <a class="reference internal" href="/wiki/display/ECFLOW/Glossary#term-task"><em class="xref std std-term">task</em></a> can set several of them</p>
<div class="section" id="ecf-script">
<h2>Ecf Script<a class="headerlink" href="#ecf-script" title="Permalink to this headline">¶</a></h2>
<div class="line-block">
<div class="line">We will create new tasks (t3, t4) that will be triggered by the events emitted in task t2.</div>
<div class="line">Create the <a class="reference internal" href="/wiki/display/ECFLOW/Glossary#term-ecf-script"><em class="xref std std-term">ecf script</em></a> for t3 and t4 by copying t1.</div>
</div>
<div class="line-block">
<div class="line">To notify <a class="reference internal" href="/wiki/display/ECFLOW/Glossary#term-ecflow-server"><em class="xref std std-term">ecflow_server</em></a>, the task (<strong>t2</strong> in the example below)</div>
<div class="line">must call <a class="reference internal" href="/wiki/display/ECFLOW/Glossary#term-ecflow-client"><em class="xref std std-term">ecflow_client</em></a> –event which is one of the <a class="reference internal" href="/wiki/display/ECFLOW/Glossary#term-child-command"><em class="xref std std-term">child command</em></a>‘s</div>
</div>
<div class="highlight-python"><pre>%include <head.h>
echo "I will now sleep for %SLEEP% seconds"
sleep %SLEEP%
ecflow_client --event a # Set the first event
sleep %SLEEP% # Sleep a bit more
ecflow_client --event b # Set the second event
sleep %SLEEP% # A last nap...
%include <tail.h></pre>
</div>
</div>
<div class="section" id="text">
<h2>Text<a class="headerlink" href="#text" title="Permalink to this headline">¶</a></h2>
<div class="highlight-python"><pre># Definition of the suite test.
suite test
edit ECF_INCLUDE "$HOME/course" # replace '$HOME' with the path to your home directory
edit ECF_HOME "$HOME/course"
family f1
edit SLEEP 20
task t1
task t2
trigger t1 eq complete
event a
event b
task t3
trigger t2:a
task t4
trigger t2:b
endfamily
endsuite</pre>
</div>
</div>
<div class="section" id="python">
<h2>Python<a class="headerlink" href="#python" title="Permalink to this headline">¶</a></h2>
<div class="highlight-python"><div class="highlight"><pre><span class="c">#!/usr/bin/env python2.7</span>
<span class="kn">import</span> <span class="nn">os</span>
<span class="kn">import</span> <span class="nn">ecflow</span>
<span class="k">def</span> <span class="nf">create_family_f1</span><span class="p">():</span>
<span class="n">f1</span> <span class="o">=</span> <span class="n">ecflow</span><span class="o">.</span><span class="n">Family</span><span class="p">(</span><span class="s">"f1"</span><span class="p">)</span>
<span class="n">f1</span><span class="o">.</span><span class="n">add_variable</span><span class="p">(</span><span class="s">"SLEEP"</span><span class="p">,</span> <span class="mi">20</span><span class="p">)</span>
<span class="n">f1</span><span class="o">.</span><span class="n">add_task</span><span class="p">(</span><span class="s">"t1"</span><span class="p">)</span>
<span class="n">t2</span> <span class="o">=</span> <span class="n">f1</span><span class="o">.</span><span class="n">add_task</span><span class="p">(</span><span class="s">"t2"</span><span class="p">)</span>
<span class="n">t2</span><span class="o">.</span><span class="n">add_trigger</span><span class="p">(</span><span class="s">"t1 eq complete"</span><span class="p">)</span>
<span class="n">t2</span><span class="o">.</span><span class="n">add_event</span><span class="p">(</span><span class="s">"a"</span><span class="p">)</span>
<span class="n">t2</span><span class="o">.</span><span class="n">add_event</span><span class="p">(</span><span class="s">"b"</span><span class="p">)</span>
<span class="n">f1</span><span class="o">.</span><span class="n">add_task</span><span class="p">(</span><span class="s">"t3"</span><span class="p">)</span><span class="o">.</span><span class="n">add_trigger</span><span class="p">(</span><span class="s">"t2:a"</span><span class="p">)</span>
<span class="n">f1</span><span class="o">.</span><span class="n">add_task</span><span class="p">(</span><span class="s">"t4"</span><span class="p">)</span><span class="o">.</span><span class="n">add_trigger</span><span class="p">(</span><span class="s">"t2:b"</span><span class="p">)</span>
<span class="k">return</span> <span class="n">f1</span>
<span class="k">print</span> <span class="s">"Creating suite definition"</span>
<span class="n">defs</span> <span class="o">=</span> <span class="n">ecflow</span><span class="o">.</span><span class="n">Defs</span><span class="p">()</span>
<span class="n">suite</span> <span class="o">=</span> <span class="n">defs</span><span class="o">.</span><span class="n">add_suite</span><span class="p">(</span><span class="s">"test"</span><span class="p">)</span>
<span class="n">suite</span><span class="o">.</span><span class="n">add_variable</span><span class="p">(</span><span class="s">"ECF_INCLUDE"</span><span class="p">,</span> <span class="n">os</span><span class="o">.</span><span class="n">getenv</span><span class="p">(</span><span class="s">"HOME"</span><span class="p">)</span> <span class="o">+</span> <span class="s">"/course"</span><span class="p">)</span>
<span class="n">suite</span><span class="o">.</span><span class="n">add_variable</span><span class="p">(</span><span class="s">"ECF_HOME"</span><span class="p">,</span> <span class="n">os</span><span class="o">.</span><span class="n">getenv</span><span class="p">(</span><span class="s">"HOME"</span><span class="p">)</span> <span class="o">+</span> <span class="s">"/course"</span><span class="p">)</span>
<span class="n">suite</span><span class="o">.</span><span class="n">add_family</span><span class="p">(</span> <span class="n">create_family_f1</span><span class="p">()</span> <span class="p">)</span>
<span class="k">print</span> <span class="n">defs</span>
<span class="k">print</span> <span class="s">"Checking job creation: .ecf -> .job0"</span>
<span class="k">print</span> <span class="n">defs</span><span class="o">.</span><span class="n">check_job_creation</span><span class="p">()</span>
<span class="k">print</span> <span class="s">"Checking trigger expressions"</span>
<span class="k">print</span> <span class="n">defs</span><span class="o">.</span><span class="n">check</span><span class="p">()</span>
<span class="k">print</span> <span class="s">"Saving definition to file 'test.def'"</span>
<span class="n">defs</span><span class="o">.</span><span class="n">save_as_defs</span><span class="p">(</span><span class="s">"test.def"</span><span class="p">)</span>
</pre></div>
</div>
<p><strong>What to do:</strong></p>
<ol class="arabic simple">
<li>Update <tt class="file docutils literal"><span class="pre">test.def</span></tt> or <tt class="file docutils literal"><span class="pre">test.py</span></tt></li>
<li>Edit <tt class="file docutils literal"><span class="pre">t2.ecf</span></tt> to call <a class="reference internal" href="/wiki/display/ECFLOW/Glossary#term-ecflow-client"><em class="xref std std-term">ecflow_client</em></a> –event.</li>
<li>Copy <tt class="file docutils literal"><span class="pre">t1.ecf</span></tt> to <tt class="file docutils literal"><span class="pre">t3.ecf</span></tt> and <tt class="file docutils literal"><span class="pre">t4.ecf</span></tt></li>
<li>Replace the <a class="reference internal" href="/wiki/display/ECFLOW/Glossary#term-suite"><em class="xref std std-term">suite</em></a></li>
<li>Observe the tasks in <a class="reference internal" href="/wiki/display/ECFLOW/Glossary#term-ecflowview"><em class="xref std std-term">ecflowview</em></a>.</li>
<li>See the triggers by selecting <strong>t3</strong> and clicking on the icon <img alt="triggers" src="../../../_images/wiki/download/attachments/7373012/triggers.jpg" /></li>
<li>See the triggers by selecting <strong>t2</strong> and click on <strong>Dependencies</strong></li>
</ol>
</div>
</div>
|