示例#1
0
        void InitializeRecoverableAction()
        {
            RecoverableAction = Substitute.For <IRecoverableAction>();
            RecoverableAction.WhenForAnyArgs(a => a.Run(null)).Do(c =>
            {
                var args = c.Args();
                try
                {
                    ((Action)args[0])();
                }
                catch (Exception)
                {
                    var recoveryAction = args[1] ?? args[0];
                    ((Action)recoveryAction)();
                }

                if (args[2] != null)
                {
                    ((Action)args[2])();
                }
            });
        }
示例#2
0
        public IScheduler CreateScheduler()
        {
            Func <DateTime> now = () => DateTime.Now;

            var eventStream                = new EventStream(_eventSinks, _exceptionLogger, now);
            var recoverableAction          = new RecoverableAction(this, eventStream);
            var delegatingPersistenceStore = new DelegatingPersistenceStore(_persistenceProvider);
            var jobMutation                = new JobMutator(eventStream, delegatingPersistenceStore);

            var queueConfiguration = new JobQueueFactory(
                delegatingPersistenceStore, this, eventStream, recoverableAction, jobMutation).Create();

            var router       = new JobRouter(queueConfiguration);
            var methodBinder = new MethodBinder();

            var continuationDispatcher = new ContinuationDispatcher(router, jobMutation,
                                                                    delegatingPersistenceStore, recoverableAction);
            var activityToContinuationConverter = new ActivityToContinuationConverter(now);

            var runningTransition = new RunningTransition(jobMutation);
            var failedTransition  = new FailedTransition(this, jobMutation, now);
            var endTransition     = new EndTransition(delegatingPersistenceStore, jobMutation,
                                                      continuationDispatcher);

            var continuationLiveness = new ContinuationLiveness(delegatingPersistenceStore, continuationDispatcher);

            var coordinator = new JobCoordinator(eventStream, recoverableAction);

            var waitingForChildrenTransition = new WaitingForChildrenTransition(
                delegatingPersistenceStore,
                continuationDispatcher,
                activityToContinuationConverter,
                recoverableAction,
                jobMutation);

            var changeState = new StatusChanger(eventStream, runningTransition, failedTransition,
                                                endTransition, waitingForChildrenTransition, jobMutation);

            var failedJobQueue = new FailedJobQueue(this, delegatingPersistenceStore, now, eventStream, router);

            var errorHandlingPolicy = new ErrorHandlingPolicy(this, coordinator, changeState,
                                                              failedJobQueue, recoverableAction);

            var exceptionFilterDispatcher = new ExceptionFilterDispatcher(eventStream);

            var jobDispatcher = new Dispatcher.Dispatcher(_dependencyResolver,
                                                          coordinator,
                                                          errorHandlingPolicy,
                                                          methodBinder,
                                                          eventStream,
                                                          recoverableAction,
                                                          changeState,
                                                          continuationLiveness,
                                                          exceptionFilterDispatcher);

            var jobPumps =
                queueConfiguration
                .ActivitySpecificQueues
                .Values
                .Select(q => new JobPump(jobDispatcher, eventStream, q))
                .ToList();

            jobPumps.Add(new JobPump(jobDispatcher, eventStream, queueConfiguration.Default));

            return(new Scheduler(
                       queueConfiguration,
                       this,
                       delegatingPersistenceStore,
                       now,
                       failedJobQueue,
                       recoverableAction,
                       router,
                       activityToContinuationConverter,
                       jobPumps,
                       jobMutation));
        }