macrobot utility complex setup seems not to work

kamcknig's Avatar

kamcknig

11 Nov, 2016 04:12 PM

Hello!

I am using the macrobot utility to run nested sequence/parallel macro commands.

My setup is something like this:

PostLoginCommand extends SequenceMacro

prepare()
{
    trace("PostLoginCommand");
    add(ChangeMerchantMacro); //extends ParallelMacro
    add(GetNewCartService); //extends AsyncCommand and uses dispatchComplete(true/false)
}
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");
}
GetKeywordsAndPacakgesMacro extends SequenceMacro

prepare()
{
    trace("GetKeywordsAndPacakgesMacro ");
    add(GetKeywordsCommand); //extends AsyncCommand and uses dispatchComplete(true/false)
    add(GetPackagesForKeywordsCommand); //extends AsynCommand and uses dispatchComplete(true/false)
}
GetKeywordsCommand

trace("GetKeywordsCommand");
GetPackagesForKeywordesCommand)

trace("GetPackagerForKeywordsCommand");
GetDetailsCommand

trace("GetDetailsCommand");
GetNewCartService

trace("GetNewCartService");

I would expect the traces to come out like so:

PostLoginCommand
ChangeMerchantMacro
GetKeywordsAndPackagesMacro
GetKeywordsCommand
GetDetailsCommand
GetPackagesForKeywordsCommand
ChangeMerchantMacro result
GetNewCartService

But the traces end up coming out like this.

PostLoginCommand
ChangeMerchantMacro
GetKeywordsAndPackagesMacro
GetKeywordsCommand
GetDetailsCommand
GetPackagesForKeywordsCommand
GetNewCartService ChangeMerchantMacro result

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.

  1. Support Staff 1 Posted by Ondina D.F. on 11 Nov, 2016 04:38 PM

    Ondina D.F.'s Avatar

    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.

    https://github.com/alebianco/robotlegs-utilities-macrobot#atomic-ex...

  2. 2 Posted by kamcknig on 11 Nov, 2016 05:10 PM

    kamcknig's Avatar

    Does atomic only have to do with if one of the commands in the macro fails?

    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.

  3. Support Staff 3 Posted by Ondina D.F. on 12 Nov, 2016 03:21 PM

    Ondina D.F.'s Avatar

    Does atomic only have to do with if one of the commands in the macro fails?

    Yep.

    Without trying it out I cannot say for sure what's wrong with the flow of your commands.

    Maybe you should not rely on the complete handler of a SequenceMacro to modify the model.
    If I understand correctly the order in which your commands should execute is:

    1. GetKeywordsCommand
    2. GetPackagesForKeywordsCommand
    3. GetDetailsCommand
    4. GetNewCartService

    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.

    I've noticed that ChangeMerchantMacro extends ParallelMacro. Why not a SequenceMacro?

    Perhaps another setup, with fewer nested sequences, could work better?

  4. Ondina D.F. closed this discussion on 21 Dec, 2016 11:37 AM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac