<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 ECF 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="highlight-python"><pre># Definition of the suite test.
suite test
edit ECF_INCLUDE "$HOME/course"
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>
<p>In python this would be like:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="c">#!/usr/bin/env python2.5</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">t3</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">"t3"</span><span class="p">)</span>
<span class="n">t3</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">t4</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">"t4"</span><span class="p">)</span>
<span class="n">t4</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="n">defs</span> <span class="o">=</span> <span class="n">ecflow</span><span class="o">.</span><span class="n">Defs</span><span >(</span><span >"test.def"</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>
</pre></div>
</div>
<div class="line-block">
<div class="line">To notify <a class="reference internal" href="/wiki/display/ECFLOW/Glossary#term-ecfecflow-server"><em >ecfclass="xref std std-term">ecflow_server</em></a>, the task <strong>t2</strong> must call</div>
<div class="line"><a class="reference internal" href="/wiki/display/ECFLOW/Glossary#term-ecfecflow-client"><em >ecfclass="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%
ecfecflow_client --event a # Set the first event
sleep %SLEEP% # Sleep a bit more
ecfecflow_client --event b # Set the second event
sleep %SLEEP% # A last nap...
%include <tail.h></pre>
</div>
<p>What to do:</p>
<ol class="arabic simple">
<li>Edit the definition or python file to add the modifications.</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-ecfecflow-client"><em >ecf 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>Load the definition again.</li>
<li>Observe the tasks in <a class="reference internal" href="/wiki/display/ECFLOW/Glossary#term-ecflowview"><em >ecFlowview< 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="../wiki../download/attachments/7373012../_images/triggers.jpg" /></li>
<li>See the triggers by selecting <strong>t2</strong> and click on <strong>Dependencies</strong></li>
</ol>
</div>
|