tag:robotlegs.tenderapp.com,2009-10-18:/discussions/robotlegs-2/17657-macrobot-utility-complex-setup-seems-not-to-workRobotlegs: Discussion 2016-12-21T11:37:08Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/412077212016-11-11T16:12:39Z2016-11-11T16:12:39Zmacrobot utility complex setup seems not to work<div><p>Hello!</p>
<p>I am using the macrobot utility to run nested sequence/parallel
macro commands.</p>
<p>My setup is something like this:</p>
<pre>
<code>PostLoginCommand extends SequenceMacro
prepare()
{
trace("PostLoginCommand");
add(ChangeMerchantMacro); //extends ParallelMacro
add(GetNewCartService); //extends AsyncCommand and uses dispatchComplete(true/false)
}</code>
</pre>
<pre>
<code>ChangeMerchantMacro extends ParallelMacro
prepare()
{
trace("ChangeMerchantMacro ");
add(GetKeywordsAndPackagesMacro); //extends SequenceMacro
add(GetDetailsCommand); //extends AsyncCommand and uses dispatchComplete(true/false)
registerCompleteCallback(handleResult);
}
handleResult(success:Boolean):void
{
trace("ChangeMerchantMacro result");
}</code>
</pre>
<pre>
<code>GetKeywordsAndPacakgesMacro extends SequenceMacro
prepare()
{
trace("GetKeywordsAndPacakgesMacro ");
add(GetKeywordsCommand); //extends AsyncCommand and uses dispatchComplete(true/false)
add(GetPackagesForKeywordsCommand); //extends AsynCommand and uses dispatchComplete(true/false)
}</code>
</pre>
<pre>
<code>GetKeywordsCommand
trace("GetKeywordsCommand");</code>
</pre>
<pre>
<code>GetPackagesForKeywordesCommand)
trace("GetPackagerForKeywordsCommand");</code>
</pre>
<pre>
<code>GetDetailsCommand
trace("GetDetailsCommand");</code>
</pre>
<pre>
<code>GetNewCartService
trace("GetNewCartService");</code>
</pre>
<p>I would expect the traces to come out like so:</p>
<p>PostLoginCommand<br>
ChangeMerchantMacro<br>
GetKeywordsAndPackagesMacro<br>
GetKeywordsCommand<br>
GetDetailsCommand<br>
GetPackagesForKeywordsCommand<br>
ChangeMerchantMacro result<br>
<strong>GetNewCartService</strong></p>
<p>But the traces end up coming out like this.</p>
<p>PostLoginCommand<br>
ChangeMerchantMacro<br>
GetKeywordsAndPackagesMacro<br>
GetKeywordsCommand<br>
GetDetailsCommand<br>
GetPackagesForKeywordsCommand<br>
<strong>GetNewCartService</strong> ChangeMerchantMacro result</p>
<p>The GetNewCartService seems to be called before my handler in
ChangeMerchantMacro. Is there anyway to get arond this? The
complete handler modifies some model data that GetNewCartService
needs, but GetNewCartService is run before the previous Macro is
technically complete.</p></div>kamcknigtag:robotlegs.tenderapp.com,2009-10-18:Comment/412077212016-11-11T16:38:27Z2016-11-11T16:38:27Zmacrobot utility complex setup seems not to work<div><p>Try to set the atomic property to false to see if that was the
issue. If it wasn't, then you'll have to debug each command step by
step.</p>
<p><a href="https://github.com/alebianco/robotlegs-utilities-macrobot#atomic-execution">
https://github.com/alebianco/robotlegs-utilities-macrobot#atomic-ex...</a></p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/412077212016-11-11T17:10:10Z2016-11-11T17:10:10Zmacrobot utility complex setup seems not to work<div><p>Does atomic only have to do with if one of the commands in the
macro fails?</p>
<p>If so then it won't matter in this case as all macros/commands
are succeeding. It's just the "race condition" of the internal
macro's registered callback being invoked after the parent macro
instantiates/executes the next command.</p></div>kamcknigtag:robotlegs.tenderapp.com,2009-10-18:Comment/412077212016-11-12T15:21:59Z2016-11-12T15:21:59Zmacrobot utility complex setup seems not to work<div><blockquote>
<p>Does atomic only have to do with if one of the commands in the
macro fails?</p>
</blockquote>
<p>Yep.</p>
<p>Without trying it out I cannot say for sure what's wrong with
the flow of your commands.</p>
<p>Maybe you should not rely on the complete handler of a
SequenceMacro to modify the model.<br>
If I understand correctly the order in which your commands should
execute is:</p>
<ol>
<li>GetKeywordsCommand<br></li>
<li>GetPackagesForKeywordsCommand<br></li>
<li>GetDetailsCommand<br></li>
<li>GetNewCartService</li>
</ol>
<p>If all commands are injected with the same model, the first 3
commands can write their results into that model and
GetNewCartService can read the final data and use it for its
requests.</p>
<p>I've noticed that ChangeMerchantMacro extends ParallelMacro. Why
not a SequenceMacro?</p>
<p>Perhaps another setup, with fewer nested sequences, could work
better?</p></div>Ondina D.F.