示例#1
0
 public SimpleJobActivatorScope([NotNull] JobActivator activator)
 {
     if (activator == null)
     {
         throw new ArgumentNullException("activator");
     }
     _activator = activator;
 }
示例#2
0
        public BackgroundJobServer(
            [NotNull] BackgroundJobServerOptions options,
            [NotNull] JobStorage storage,
            [NotNull] IEnumerable <IBackgroundProcess> additionalProcesses,
            [CanBeNull] IJobFilterProvider filterProvider,
            [CanBeNull] JobActivator activator,
            [CanBeNull] IBackgroundJobFactory factory,
            [CanBeNull] IBackgroundJobPerformer performer,
            [CanBeNull] IBackgroundJobStateChanger stateChanger)
        {
            if (storage == null)
            {
                throw new ArgumentNullException(nameof(storage));
            }
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }
            if (additionalProcesses == null)
            {
                throw new ArgumentNullException(nameof(additionalProcesses));
            }

            _options = options;

            var processes = new List <IBackgroundProcessDispatcherBuilder>();

            processes.AddRange(GetRequiredProcesses(filterProvider, activator, factory, performer, stateChanger));
            processes.AddRange(additionalProcesses.Select(x => x.UseBackgroundPool(1)));

            var properties = new Dictionary <string, object>
            {
                { "Queues", options.Queues },
                { "WorkerCount", options.WorkerCount }
            };

            _logger.Info($"Starting Hangfire Server using job storage: '{storage}'");

            storage.WriteOptionsToLog(_logger);

            _logger.Info("Using the following options for Hangfire Server:\r\n" +
                         $"    Worker count: {options.WorkerCount}\r\n" +
                         $"    Listening queues: {String.Join(", ", options.Queues.Select(x => "'" + x + "'"))}\r\n" +
                         $"    Shutdown timeout: {options.ShutdownTimeout}\r\n" +
                         $"    Schedule polling interval: {options.SchedulePollingInterval}");

            _processingServer = new BackgroundProcessingServer(
                storage,
                processes,
                properties,
                GetProcessingServerOptions());
        }
示例#3
0
        private IEnumerable <IBackgroundProcessDispatcherBuilder> GetRequiredProcesses(
            [CanBeNull] IJobFilterProvider filterProvider,
            [CanBeNull] JobActivator activator,
            [CanBeNull] IBackgroundJobFactory factory,
            [CanBeNull] IBackgroundJobPerformer performer,
            [CanBeNull] IBackgroundJobStateChanger stateChanger)
        {
            var processes        = new List <IBackgroundProcessDispatcherBuilder>();
            var timeZoneResolver = _options.TimeZoneResolver ?? new DefaultTimeZoneResolver();

            if (factory == null && performer == null && stateChanger == null)
            {
                filterProvider = filterProvider ?? _options.FilterProvider ?? JobFilterProviders.Providers;
                activator      = activator ?? _options.Activator ?? JobActivator.Current;

                factory      = new BackgroundJobFactory(filterProvider);
                performer    = new BackgroundJobPerformer(filterProvider, activator, _options.TaskScheduler);
                stateChanger = new BackgroundJobStateChanger(filterProvider);
            }
            else
            {
                if (factory == null)
                {
                    throw new ArgumentNullException(nameof(factory));
                }
                if (performer == null)
                {
                    throw new ArgumentNullException(nameof(performer));
                }
                if (stateChanger == null)
                {
                    throw new ArgumentNullException(nameof(stateChanger));
                }
            }

            processes.Add(new Worker(_options.Queues, performer, stateChanger).UseBackgroundPool(_options.WorkerCount));
            processes.Add(new DelayedJobScheduler(_options.SchedulePollingInterval, stateChanger).UseBackgroundPool(1));
            processes.Add(new RecurringJobScheduler(factory, _options.SchedulePollingInterval, timeZoneResolver).UseBackgroundPool(1));

            return(processes);
        }
示例#4
0
        private IEnumerable <IBackgroundProcess> GetRequiredProcesses(
            [NotNull] IJobFilterProvider filterProvider,
            [NotNull] JobActivator activator,
            [CanBeNull] IBackgroundJobFactory factory,
            [CanBeNull] IBackgroundJobPerformer performer,
            [CanBeNull] IBackgroundJobStateChanger stateChanger)
        {
            var processes = new List <IBackgroundProcess>();

            factory      = factory ?? new BackgroundJobFactory(filterProvider);
            performer    = performer ?? new BackgroundJobPerformer(filterProvider, activator);
            stateChanger = stateChanger ?? new BackgroundJobStateChanger(filterProvider);

            for (var i = 0; i < _options.WorkerCount; i++)
            {
                processes.Add(new Worker(_options.Queues, performer, stateChanger));
            }

            processes.Add(new DelayedJobScheduler(_options.SchedulePollingInterval, stateChanger));
            processes.Add(new RecurringJobScheduler(factory));

            return(processes);
        }
 public void UseActivator(JobActivator activator)
 {
     Activator = activator;
 }
 public HangfireIocJobActivatorScope(JobActivator activator, IIocResolver iocResolver)
 {
     _activator = activator;
     _iocResolver = iocResolver;
     _resolvedObjects = new List<object>();
 }
 public void UseActivator(JobActivator activator)
 {
     Activator = activator;
 }
示例#8
0
 public SimpleJobActivatorScope([NotNull] JobActivator activator)
 {
     if (activator == null) throw new ArgumentNullException("activator");
     _activator = activator;
 }