Exemple #1
0
        public Worker(
            [NotNull] WorkerContext context,
            [NotNull] JobStorage storage,
            [NotNull] IJobPerformanceProcess process,
            [NotNull] IStateMachineFactory stateMachineFactory)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            if (storage == null)
            {
                throw new ArgumentNullException("storage");
            }
            if (process == null)
            {
                throw new ArgumentNullException("process");
            }
            if (stateMachineFactory == null)
            {
                throw new ArgumentNullException("stateMachineFactory");
            }

            _context             = context;
            _storage             = storage;
            _process             = process;
            _stateMachineFactory = stateMachineFactory;
        }
        public void CopyCtor_CorrectlyCopies_AllPropertyValues()
        {
            var context = CreateContext();
            var contextCopy = new WorkerContext(context);

            Assert.Equal(context.WorkerNumber, contextCopy.WorkerNumber);
        }
Exemple #3
0
        internal PerformContext(
            WorkerContext workerContext,
            IStorageConnection connection,
            string jobId,
            Job job,
            DateTime createdAt,
            IJobCancellationToken cancellationToken)
            : base(workerContext)
        {
            if (connection == null)
            {
                throw new ArgumentNullException("connection");
            }
            if (jobId == null)
            {
                throw new ArgumentNullException("jobId");
            }
            if (job == null)
            {
                throw new ArgumentNullException("job");
            }
            if (cancellationToken == null)
            {
                throw new ArgumentNullException("cancellationToken");
            }

            Connection        = connection;
            JobId             = jobId;
            Job               = job;
            CreatedAt         = createdAt;
            CancellationToken = cancellationToken;

            Items = new Dictionary <string, object>();
        }
Exemple #4
0
 internal virtual IServerSupervisor CreateWorkerSupervisor(WorkerContext context)
 {
     return(new ServerSupervisor(
                new AutomaticRetryServerComponentWrapper(new Worker(context)),
                new ServerSupervisorOptions {
         LowerLogVerbosity = true
     }));
 }
Exemple #5
0
 internal virtual IServerSupervisor CreateWorkerSupervisor(WorkerContext context)
 {
     return(new ServerSupervisor(
                new Worker(context),
                new ServerSupervisorOptions {
         LowerLogVerbosity = true
     }));
 }
Exemple #6
0
        public Worker(WorkerContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            _context = context;
        }
        public void CreateWorkerSupervisor_CreatesAWorkerSupervisorWithGivenParameters()
        {
            var manager = new WorkerManager(_sharedContext, WorkerCount);
            var context = new WorkerContext(_sharedContext, 1);

            var worker = manager.CreateWorkerSupervisor(context);

            Assert.NotNull(worker);
        }
        public ServerJobCancellationToken(
            [NotNull] string jobId, 
            [NotNull] IStorageConnection connection, 
            [NotNull] WorkerContext workerContext,
            CancellationToken shutdownToken)
        {
            if (jobId == null) throw new ArgumentNullException("jobId");
            if (connection == null) throw new ArgumentNullException("connection");
            if (workerContext == null) throw new ArgumentNullException("workerContext");

            _jobId = jobId;
            _shutdownToken = shutdownToken;
            _connection = connection;
            _workerContext = workerContext;
        }
Exemple #9
0
 public Worker(
     [NotNull] WorkerContext context,
     [NotNull] JobStorage storage, 
     [NotNull] IJobPerformanceProcess process, 
     [NotNull] IStateMachineFactory stateMachineFactory)
 {
     if (context == null) throw new ArgumentNullException("context");
     if (storage == null) throw new ArgumentNullException("storage");
     if (process == null) throw new ArgumentNullException("process");
     if (stateMachineFactory == null) throw new ArgumentNullException("stateMachineFactory");
     
     _context = context;
     _storage = storage;
     _process = process;
     _stateMachineFactory = stateMachineFactory;
 }
Exemple #10
0
        public void Execute(CancellationToken cancellationToken)
        {
            var workerSupervisors = new List<IServerSupervisor>(_workerCount);
            for (var i = 1; i <= _workerCount; i++)
            {
                var workerContext = new WorkerContext(_sharedContext, i);

                // ReSharper disable once DoNotCallOverridableMethodsInConstructor
                workerSupervisors.Add(CreateWorkerSupervisor(workerContext));
            }

            using (var supervisors = new ServerSupervisorCollection(workerSupervisors))
            {
                supervisors.Start();
                cancellationToken.WaitHandle.WaitOne();
            }
        }
Exemple #11
0
        public void Execute(CancellationToken cancellationToken)
        {
            var workerSupervisors = new List <IServerSupervisor>(_workerCount);

            for (var i = 1; i <= _workerCount; i++)
            {
                var workerContext = new WorkerContext(_sharedContext, i);

                // ReSharper disable once DoNotCallOverridableMethodsInConstructor
                workerSupervisors.Add(CreateWorkerSupervisor(workerContext));
            }

            using (var supervisors = new ServerSupervisorCollection(workerSupervisors))
            {
                supervisors.Start();
                cancellationToken.WaitHandle.WaitOne();
            }
        }
Exemple #12
0
        public ServerJobExecutionContext(
            [NotNull] string jobId,
            [NotNull] IStorageConnection connection,
            [NotNull] WorkerContext workerContext,
            CancellationToken shutdownToken)
        {
            if (jobId == null)
            {
                throw new ArgumentNullException("jobId");
            }
            if (connection == null)
            {
                throw new ArgumentNullException("connection");
            }
            if (workerContext == null)
            {
                throw new ArgumentNullException("workerContext");
            }

            _jobId         = jobId;
            _shutdownToken = shutdownToken;
            _connection    = connection;
            _workerContext = workerContext;
        }
Exemple #13
0
 internal WorkerContext(WorkerContext workerContext)
     : this (workerContext.ServerId, workerContext.Queues, workerContext.WorkerNumber)
 {
 }
Exemple #14
0
        public Worker(WorkerContext context)
        {
            if (context == null) throw new ArgumentNullException("context");

            _context = context;
        }
Exemple #15
0
 internal WorkerContext(WorkerContext workerContext)
     : this (workerContext, workerContext.WorkerNumber)
 {
 }
        private IEnumerable<IServerComponent> GetCommonComponents()
        {
            var performanceProcess = new DefaultJobPerformanceProcess(JobActivator.Current);
            var stateMachineFactory = new StateMachineFactory(_storage);

            for (var i = 0; i < _options.WorkerCount; i++)
            {
                var context = new WorkerContext(_serverId, _options.Queues, i + 1);
                yield return new Worker(context, _storage, performanceProcess, stateMachineFactory);
            }

            yield return new ServerHeartbeat(_storage, _serverId);
            yield return new SchedulePoller(_storage, stateMachineFactory, _options.SchedulePollingInterval);
            yield return new ServerWatchdog(_storage, _options.ServerWatchdogOptions);

            yield return new RecurringJobScheduler(
                _storage, 
                new BackgroundJobClient(_storage, stateMachineFactory),
                new ScheduleInstantFactory(),
				SchedulerResolution.Current.CreateThrottler());
        }
Exemple #17
0
 internal WorkerContext(WorkerContext workerContext)
     : this(workerContext, workerContext.WorkerNumber)
 {
 }
Exemple #18
0
 internal WorkerContext(WorkerContext workerContext)
     : this(workerContext.ServerId, workerContext.Queues, workerContext.WorkerNumber)
 {
 }
Exemple #19
0
 internal virtual IServerSupervisor CreateWorkerSupervisor(WorkerContext context)
 {
     return new ServerSupervisor(
         new Worker(context),
         new ServerSupervisorOptions { LowerLogVerbosity = true });
 }