Waiting

One of the main features of Flower workflows is that they can be stopped in the middle of processing and unloaded, so that they doesn't consume resources of the processor. The blocking activities in Flower, if they cannot perform operation in the moment of invocation, switch a process to the waiting state in which it can be unloaded. However, a processor doesn't unload a process immediately, but only after some timeout, so that processes switching between waiting and active state frequently do that efficiently.

The following statements covered in other sections can switch a process to the waiting state:
  • ForEach.
  • Enqueue.
  • Dequeue.
  • Put.
  • Lock.
  • BeginLock.

Additionally, there are statements to explicitly set a process waiting.

The JoinProcess statement allows to join a parallel process.

...
.StartProcess              //Spawning a parallel process.
(
    _ => "MySubProcess",   // Workflow path.
    _ => ... ,             // Argument to the Initialize method of
                           // the workflow.
    (_, newPid, result) => 
    {
        ...                // Processing result.
        pid = newPid;
    }
)
...
... // Doing work in parallel.
...
.JoinProcess(_ => pid) // This statement blocks until the spawned
...                    // process is finished.
...

The WaitUntil statement allows to stop a process until some moment in time.

...
.WaitUntil // Stops the process for 30 minutes.
(
    _ => DateTime.Now + TimeSpan.FromMinutes(30)
)
...

You may have noticed that none of the blocking statements allow to specify timeout. Instead of placing timeout parameter to all statements, Flower allows to wait for multiple events simultaneously by using WaitAny statement.

Suppose you need to limit the time your process can wait for another process. To achieve that, you need to unite the examples above via WaitAny statement.

...
.WaitAny()
    .JoinProcess(_ => pid, _ => { isTimeout = false; })
    .WaitUntil
    (
        _ => DateTime.Now + TimeSpan.FromMinutes(30),
        _ => { isTimeout = true; }
    )
.End()
...

The WaitAny statement encloses any number of blocking statements and passes through if any of them has performed its operation. Each of the blocking statements has an action executed before leaving WaitAny, so, by setting different statuses in each, you can determine which one has fired. This approach can be used not only for implementing timeout, but also for processing messages from multiple queues.

The following statements may appear in WaitAny:
  • Enqueue.
  • Dequeue.
  • Put.
  • Lock.
  • JoinProcess.
  • WaitUntil.

Last edited Apr 17, 2013 at 7:41 PM by dbratus, version 2

Comments

No comments yet.