Beispiel #1
0
        public Worker(JobStorage storage, WorkerContext context)
        {
            _storage = storage;
            _context = context;

            _logger = LogManager.GetLogger(String.Format("HangFire.Worker.{0}", context.WorkerNumber));
        }
Beispiel #2
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>();
        }
        public void CopyCtor_CorrectlyCopies_AllPropertyValues()
        {
            var context = CreateContext();
            var contextCopy = new WorkerContext(context);

            Assert.Equal(context.WorkerNumber, contextCopy.WorkerNumber);
        }
Beispiel #4
0
 internal virtual IServerSupervisor CreateWorkerSupervisor(WorkerContext context)
 {
     return(new ServerSupervisor(
                new Worker(context),
                new ServerSupervisorOptions {
         LowerLogVerbosity = true
     }));
 }
        public void CreateWorkerSupervisor_CreatesAWorkerSupervisorWithGivenParameters()
        {
            var manager = new WorkerManager(_sharedContext, WorkerCount);
            var context = new WorkerContext(_sharedContext, 1);

            var worker = manager.CreateWorkerSupervisor(context);

            Assert.NotNull(worker);
        }
Beispiel #6
0
        public Worker(WorkerContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            _context = context;
        }
Beispiel #7
0
        public WorkerManager(JobStorage storage, ServerContext context, int workerCount)
        {
            _workers = new DisposableCollection<Worker>();

            for (var i = 1; i <= workerCount; i++)
            {
                var workerContext = new WorkerContext(context, i);

                var worker = new Worker(storage, workerContext);
                worker.Start();

                _workers.Add(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;
        }
Beispiel #9
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();
            }
        }
Beispiel #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();
            }
        }
        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;
        }
Beispiel #12
0
        public Worker(WorkerContext context)
        {
            if (context == null) throw new ArgumentNullException("context");

            _context = context;
        }
Beispiel #13
0
 internal WorkerContext(WorkerContext workerContext)
     : this (workerContext, workerContext.WorkerNumber)
 {
 }
Beispiel #14
0
 internal virtual IServerSupervisor CreateWorkerSupervisor(WorkerContext context)
 {
     return new ServerSupervisor(
         new Worker(context),
         new ServerSupervisorOptions { LowerLogVerbosity = true });
 }
Beispiel #15
0
 internal WorkerContext(WorkerContext workerContext)
     : this(workerContext, workerContext.WorkerNumber)
 {
 }