コード例 #1
0
        public void Transit(WorkItem workItem, IEngine engine)
        {
            var exceptionId = workItem.ExceptionId.Value;
            var exception = _dataStore.Get(exceptionId);
            var current = workItem;
            current = _repository.GetParent(current);

            while (current != null)
            {
                if (current.Status.IsFinal())
                    return;

                if (current.Type == WorkflowType.Retry) //todo: add unit test
                {
                    engine.Kick(current.Id);
                    return;
                }

                if (TryRescure(current, exception, exceptionId))
                    break;

                current = _repository.GetParent(current);
            }

            if (current == null)
            {
                engine.Kick(null);
                return;
            }

            engine.Kick(current.ParentId);
        }
コード例 #2
0
        public void Transit(WorkItem workItem, IEngine engine)
        {
            if (workItem == null) throw new ArgumentNullException("workItem");
            if (workItem.Type != WorkflowType.Sequence) throw new ArgumentException("type must be sequence");

            var status = workItem.Status;

            switch (status)
            {
                case WorkItemStatus.Created:
                    _repository.DeleteChildren(workItem.Id);

                    var children = _workItemBuilder.BuildChildren(workItem);

                    _repository.AddAll(children);

                    workItem.Status = WorkItemStatus.WaitingForChildren;
                    _repository.Update(workItem);

                    engine.Kick(workItem.Id);

                    break;
                case WorkItemStatus.WaitingForChildren:
                    if (_repository.HasFailedChildren(workItem.Id))
                        return;

                    var inProgress = _repository.CountInProgressChildren(workItem.Id);

                    if (inProgress == 0)
                    {
                        var next = _repository.FindRunnableChildrenByOrder(workItem.Id, 1).SingleOrDefault();

                        if (next == null) // all complete
                        {
                            var last = _repository.GetLastChildByOrder(workItem.Id);

                            workItem.OutputId = last.OutputId;

                            workItem.Status = WorkItemStatus.Completed;
                            _repository.Update(workItem);

                            engine.Kick(workItem.ParentId);
                        }
                        else
                        {
                            if (next.Order > 0)
                            {
                                var previous = _repository.GetChildByOrder(workItem.Id, next.Order - 1);
                                next.InputId = previous.OutputId;
                                _repository.Update(next);
                            }

                            engine.Kick(next.Id);
                        }
                    }

                    break;
            }
        }
コード例 #3
0
        public void Transit(WorkItem workItem, IEngine engine)
        {
            if (workItem == null) throw new ArgumentNullException("workItem");
            if (workItem.Type != WorkflowType.Fork) throw new ArgumentException("type must be fork");

            var status = workItem.Status;
            var definition = (ForkBlock) _workflowPathNavigator.Find(workItem.WorkflowPath);

            switch (status)
            {
                case WorkItemStatus.Created:
                    _repository.DeleteChildren(workItem.Id);

                    var children = _workItemBuilder.BuildChildren(workItem);

                    _repository.AddAll(children);

                    workItem.Status = WorkItemStatus.WaitingForChildren;
                    _repository.Update(workItem);

                    engine.Kick(workItem.Id);

                    break;
                case WorkItemStatus.WaitingForChildren:
                    if (_repository.HasFailedChildren(workItem.Id))
                        return;

                    var inProgress = _repository.CountInProgressChildren(workItem.Id);
                    var newWorkers = definition.MaxWorkers - inProgress;

                    if (newWorkers > 0)
                    {
                        var workItems = _repository.FindRunnableChildrenByOrder(workItem.Id, newWorkers);
                        if (workItems.Count > 0)
                        {
                            foreach (var runnable in workItems)
                            {
                                engine.Kick(runnable.Id);
                            }
                        }
                        else if (inProgress == 0)
                        {
                            var ids = _repository.LoadChildOutputIds(workItem.Id);
                            workItem.OutputId = _dataStore.AddReferences(workItem.JobId, ids,
                                definition.Child.OutputType);
                            workItem.Status = WorkItemStatus.Completed;
                            _repository.Update(workItem);

                            engine.Kick(workItem.ParentId);
                        }
                    }

                    break;
            }
        }
コード例 #4
0
        public void Transit(WorkItem workItem, IEngine engine)
        {
            if (workItem == null) throw new ArgumentNullException("workItem");
            if (workItem.Type != WorkflowType.Retry) throw new ArgumentException("type must be retry");

            var status = workItem.Status;

            switch (status)
            {
                case WorkItemStatus.Created:
                    _repository.DeleteChildren(workItem.Id);

                    var children = _workItemBuilder.BuildChildren(workItem);

                    _repository.AddAll(children);

                    workItem.Status = WorkItemStatus.WaitingForChildren;
                    _repository.Update(workItem);

                    engine.Kick(workItem.Id);
                    break;
                case WorkItemStatus.WaitingForChildren:
                    var last = _repository.GetLastChildByOrder(workItem.Id);
                    var definition = (RetryBlock) _navigator.Find(workItem.WorkflowPath);

                    switch (last.Status)
                    {
                        case WorkItemStatus.Created:
                            engine.Kick(last.Id);
                            break;
                        case WorkItemStatus.Completed:
                            workItem.OutputId = last.OutputId;
                            workItem.Status = WorkItemStatus.Completed;

                            _repository.Update(workItem);

                            engine.Kick(workItem.ParentId);
                            break;
                        case WorkItemStatus.Failed:
                            if (last.Order < definition.RetryCount)
                            {
                                var newItem = last.Retry();

                                _repository.Add(newItem);

                                engine.Kick(newItem.Id);
                            }
                            else
                            {
                                workItem.ExceptionId = last.ExceptionId;
                                workItem.Status = WorkItemStatus.Failed;

                                _repository.Update(workItem);

                                engine.Rescure(workItem.Id);
                            }
                            break;
                    }
                    break;
            }
        }