<div id="add-trigger"> <span id="index-0"></span><span id="id1"></span> <div > <div >In the previous exercise we saw that the two tasks were running simultaneously.</div> <div >We would like now to make sure that <strong>t2</strong> only runs once <strong>t1</strong> is complete.</div> <div >For this we have to define a <a href="/wiki/display/ECFLOW/Glossary#term-trigger"><em >trigger</em></a></div> </div> <div ><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 endfamily endsuite</pre> </div> <p>In python this would be:</p> <div ><div ><pre><span >##!/usr/bin/env python2.5</span> <span >import</span> <span >os</span> <span >import</span> <span >ecflow</span> <span >def</span> <span >create_family_f1</span><span >():</span> <span >f1</span> <span >=</span> <span >ecflow</span><span >.</span><span >Family</span><span >(</span><span >"f1"</span><span >)</span> <span >f1</span><span >.</span><span >add_variable</span><span >(</span><span >"SLEEP"</span><span >,</span><span >20</span><span >)</span> <span >f1</span><span >.</span><span >add_task</span><span >(</span><span >"t1"</span><span >)</span> <span >t2</span> <span >=</span> <span >f1</span><span >.</span><span >add_task</span><span >(</span><span >"t2"</span><span >)</span> <span >t2</span><span >.</span><span >add_trigger</span><span >(</span><span >"t1 eq complete"</span><span >)</span> <span >return</span> <span >f1</span> <span >defs</span> <span >=</span> <span >ecflow</span><span >.</span><span >Defs</span><span >()</span> <span >suite</span> <span >=</span> <span >defs</span><span >.</span><span >add_suite</span><span >(</span><span >"test"</span><span >)</span> <span >suite</span><span >.</span><span >add_variable</span><span >(</span><span >"ECF_INCLUDE"</span><span >,</span><span >os</span><span >.</span><span >getenv</span><span >(</span><span >"HOME"</span><span >)</span> <span >+</span> <span >"/course"</span><span >)</span> <span >suite</span><span >.</span><span >add_variable</span><span >(</span><span >"ECF_HOME "</span><span >,</span><span >os</span><span >.</span><span >getenv</span><span >(</span><span >"HOME"</span><span >)</span> <span >+</span> <span >"/course"</span><span >)</span> <span >suite</span><span >.</span><span >add_family</span><span >(</span> <span >create_family_f1</span><span >()</span> <span >)</span> </pre></div> </div> <div > <div >Triggers are used to declare <a href="/wiki/display/ECFLOW/Glossary#term-dependencies"><em >dependencies</em></a> between two tasks.</div> <div >For instance, the second task might need data created by the first task.</div> </div> <div > <div >When ecFlow tries to start a task, it evaluates the <a href="/wiki/display/ECFLOW/Glossary#term-trigger"><em >trigger</em></a> expression.</div> <div >If the condition is correct, the task is started, otherwise the task</div> <div >stays <a href="/wiki/display/ECFLOW/Glossary#term-queued"><em >queued</em></a>.</div> </div> <div > <div >Triggers can be between tasks, or between families, or a mixture.</div> <div >Remember the two rules:</div> </div> <ul > <li>A family is <a href="/wiki/display/ECFLOW/Glossary#term-complete"><em >complete</em></a> when all its tasks are <a href="/wiki/display/ECFLOW/Glossary#term-complete"><em >complete</em></a>.</li> <li>A task will be started if its triggers and the triggers of all is parent families evaluate to true.</li> </ul> <div > <div >A <a href="/wiki/display/ECFLOW/Glossary#term-node"><em >node</em></a> can only have one trigger expression, but very complex</div> <div >expressions can be built (and keep in mind that the triggers of the</div> <div >parent nodes are also implicit triggers).</div> </div> <div > <div >Sometimes triggers are also used to prevent too many jobs from running</div> <div >at the same time. In this case the use of a <a href="/wiki/display/ECFLOW/Glossary#term-limit"><em >limit</em></a> may be a better</div> <div >solution (we will cover limits later on in the <a href="/wiki/display/ECFLOW/Limits#limits"><em>Limits</em></a> section).</div> </div> <div > <div >Triggers can be very complex, and ecFlow supports all kinds of conditions</div> <div >(not, and, or, ...)</div> </div> <p>What to do:</p> <ol > <li>Edit the <a href="/wiki/display/ECFLOW/Glossary#term-suite-definition"><em >suite definition</em></a> file to add the <a href="/wiki/display/ECFLOW/Glossary#term-trigger"><em >trigger</em></a>.</li> <li>Play the definition again.</li> <li>Observe the tasks in <a href="/wiki/display/ECFLOW/Glossary#term-ecflowview"><em >ecflowview</em></a>.</li> <li>See the triggers by selecting <strong>t1</strong> or <strong>t2</strong> and clicking on the <img alt="triggers" src="/wiki/download/attachments/7373012/triggers.jpg" /> icon.</li> <li>See the trigger relation by clicking on the arrow.</li> <li>See the triggers in the tree, using the Show menu.</li> <li>Search any reference to <strong>t1</strong> by using the <img alt="search" src="/wiki/download/attachments/7373012/search.jpg" /> icon</li> </ol> </div> |