Esempio n. 1
0
        private void ProcessQueue(IWorkContext context, Queue <int> queue, IDictionary <int, TaskReference> taskReferences)
        {
            context = context.WithTag(_tag);

            while (queue.Count > 0 && taskReferences.Count < MaxParallel)
            {
                int            nodeId = queue.Dequeue();
                WorkflowVertex vertex = Vertices[nodeId];
                context.EventLog.Verbose(context, $"Starting state manager for nodeId={nodeId}");

                var manager = new StateManagerBuilder()
                              .Add(vertex.StateItems)
                              .Build();

                vertex.State = WorkflowState.Running;
                Task t = Task.Run(() => manager.RunAsync(context));
                taskReferences.Add(nodeId, new TaskReference(t, nodeId));
            }

            if (taskReferences.Count > 0)
            {
                Task[] waitTasks = taskReferences.Values.Select(x => x.Task).ToArray();
                int    index     = Task.WaitAny(waitTasks, context.CancellationToken);
                waitTasks[index].Wait();
            }

            taskReferences.Values
            .Where(x => x.Task.IsCompleted)
            .Do(x => Vertices[x.NodeId].State = WorkflowState.Completed)
            .ToList()
            .Do(x => context.EventLog.Verbose(context, $"NodeId={x.NodeId} state manager has been completed"))
            .Run(x => taskReferences.Remove(x.NodeId));
        }
Esempio n. 2
0
        public StateManager(StateManagerBuilder builder)
        {
            Verify.IsNotNull(nameof(builder), builder);

            StateItems = new List <IStateItem>(builder.StateItems);
            Notify     = builder.Notify;
        }