コード例 #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;
        }
コード例 #2
0
ファイル: WorkerContextFacts.cs プロジェクト: atonse/Hangfire
        public void CopyCtor_CorrectlyCopies_AllPropertyValues()
        {
            var context = CreateContext();
            var contextCopy = new WorkerContext(context);

            Assert.Equal(context.WorkerNumber, contextCopy.WorkerNumber);
        }
コード例 #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>();
        }
コード例 #4
0
ファイル: WorkerManager.cs プロジェクト: swiggins/Hangfire
 internal virtual IServerSupervisor CreateWorkerSupervisor(WorkerContext context)
 {
     return(new ServerSupervisor(
                new AutomaticRetryServerComponentWrapper(new Worker(context)),
                new ServerSupervisorOptions {
         LowerLogVerbosity = true
     }));
 }
コード例 #5
0
ファイル: WorkerManager.cs プロジェクト: saeidmh83/Hangfire
 internal virtual IServerSupervisor CreateWorkerSupervisor(WorkerContext context)
 {
     return(new ServerSupervisor(
                new Worker(context),
                new ServerSupervisorOptions {
         LowerLogVerbosity = true
     }));
 }
コード例 #6
0
ファイル: Worker.cs プロジェクト: ghuntley/Hangfire
        public Worker(WorkerContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            _context = context;
        }
コード例 #7
0
ファイル: WorkerManagerFacts.cs プロジェクト: atonse/Hangfire
        public void CreateWorkerSupervisor_CreatesAWorkerSupervisorWithGivenParameters()
        {
            var manager = new WorkerManager(_sharedContext, WorkerCount);
            var context = new WorkerContext(_sharedContext, 1);

            var worker = manager.CreateWorkerSupervisor(context);

            Assert.NotNull(worker);
        }
コード例 #8
0
        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;
        }
コード例 #9
0
ファイル: Worker.cs プロジェクト: djrineh/Hangfire
 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;
 }
コード例 #10
0
ファイル: WorkerManager.cs プロジェクト: atonse/Hangfire
        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();
            }
        }
コード例 #11
0
ファイル: WorkerManager.cs プロジェクト: swiggins/Hangfire
        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();
            }
        }
コード例 #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;
        }
コード例 #13
0
ファイル: WorkerContext.cs プロジェクト: djrineh/Hangfire
 internal WorkerContext(WorkerContext workerContext)
     : this (workerContext.ServerId, workerContext.Queues, workerContext.WorkerNumber)
 {
 }
コード例 #14
0
ファイル: Worker.cs プロジェクト: jerry4/Hangfire
        public Worker(WorkerContext context)
        {
            if (context == null) throw new ArgumentNullException("context");

            _context = context;
        }
コード例 #15
0
ファイル: WorkerContext.cs プロジェクト: atonse/Hangfire
 internal WorkerContext(WorkerContext workerContext)
     : this (workerContext, workerContext.WorkerNumber)
 {
 }
コード例 #16
0
        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());
        }
コード例 #17
0
 internal WorkerContext(WorkerContext workerContext)
     : this(workerContext, workerContext.WorkerNumber)
 {
 }
コード例 #18
0
 internal WorkerContext(WorkerContext workerContext)
     : this(workerContext.ServerId, workerContext.Queues, workerContext.WorkerNumber)
 {
 }
コード例 #19
0
ファイル: WorkerManager.cs プロジェクト: atonse/Hangfire
 internal virtual IServerSupervisor CreateWorkerSupervisor(WorkerContext context)
 {
     return new ServerSupervisor(
         new Worker(context),
         new ServerSupervisorOptions { LowerLogVerbosity = true });
 }