amazon-web-servicesamazon-swf

can we have class level variable to store activity results in SWF flow's workflow worker?


In all the SWF Flow documentation for deciders, it's mentioned that the deciders should be deterministic and no random variables should be used in the workflow worker. But I was wondering if we can have class level variables in workflow workers that stores the activity results, so that we can use the results subsequently in the follwing activities..

In the replay scenario, SWF re-populates all the Promises for the activities that are completed. Does this mean we can store only Promises that are returned or directly the objects that Promises carry


Solution

  • Yes, absolutely. The workflows are stateful and can have fields that store any data.

    Don't think about replay when writing workflow code. If your code is deterministic then you just treat it as normal code and the framework takes care of recovering the state of infra failures.

    BTW. Check out temporal.io which is a much more polished open source version of SWF. For example, it allows writing workflow code synchronously with activity invocations blocking as long as necessary.

    Disclaimer: I'm original tech lead of SWF and the current lead of Temporal.