public static (BackgroundJobServer server, IRecurringJobManager recurringJobManager, IBackgroundJobClient backgroundJobClient) StartHangfireServer(
            string tenantId,
            string serverName,
            string connectionString,
            IApplicationLifetime applicationLifetime,
            IJobFilterProvider jobFilters,
            MultitenantContainer mtc,
            IBackgroundJobFactory backgroundJobFactory,
            IBackgroundJobPerformer backgroundJobPerformer,
            IBackgroundJobStateChanger backgroundJobStateChanger,
            IBackgroundProcess[] additionalProcesses
            )
        {
            var tenantJobActivator = new AspNetCoreMultiTenantJobActivator(mtc, tenantId);

            return(HangfireHelper.StartHangfireServer(
                       serverName,
                       connectionString,
                       applicationLifetime,
                       jobFilters,
                       tenantJobActivator,
                       backgroundJobFactory,
                       backgroundJobPerformer,
                       backgroundJobStateChanger,
                       additionalProcesses));
        }
Пример #2
0
        public static (BackgroundJobServer server, IRecurringJobManager recurringJobManager, IBackgroundJobClient backgroundJobClient) StartHangfireServer(
            string serverName,
            string connectionString,
            IApplicationLifetime applicationLifetime,
            IJobFilterProvider jobFilters,
            JobActivator jobActivator,
            IBackgroundJobFactory backgroundJobFactory,
            IBackgroundJobPerformer backgroundJobPerformer,
            IBackgroundJobStateChanger backgroundJobStateChanger,
            IBackgroundProcess[] additionalProcesses
            )
        {
            var options = new BackgroundJobServerOptions
            {
                ServerName = serverName,
                Queues     = new string[] { serverName, "default" }
            };

            return(StartHangfireServer(
                       options,
                       connectionString,
                       applicationLifetime,
                       jobFilters,
                       jobActivator,
                       backgroundJobFactory,
                       backgroundJobPerformer,
                       backgroundJobStateChanger,
                       additionalProcesses
                       ));
        }
Пример #3
0
 public AppTenantsInitializer(
     AppTenantsContext context,
     IConfiguration configuration,
     IHostingEnvironment environment,
     IApplicationLifetime applicationLifetime,
     IJobFilterProvider jobFilters,
     MultitenantContainer multiTenantContainer,
     IBackgroundJobFactory backgroundJobFactory,
     IBackgroundJobPerformer backgroundJobPerformer,
     IBackgroundJobStateChanger backgroundJobStateChanger,
     IBackgroundProcess[] additionalProcesses,
     ITenantConfiguration[] tenantConfigurations)
 {
     _context                   = context;
     _configuration             = configuration;
     _environment               = environment;
     _applicationLifetime       = applicationLifetime;
     _jobFilters                = jobFilters;
     _multiTenantContainer      = multiTenantContainer;
     _backgroundJobFactory      = backgroundJobFactory;
     _backgroundJobPerformer    = backgroundJobPerformer;
     _backgroundJobStateChanger = backgroundJobStateChanger;
     _additionalProcesses       = additionalProcesses;
     _tenantConfigurations      = tenantConfigurations;
 }
Пример #4
0
 public RecurringJobManager(
     [NotNull] JobStorage storage,
     [NotNull] IJobFilterProvider filterProvider,
     [NotNull] ITimeZoneResolver timeZoneResolver)
     : this(storage, filterProvider, timeZoneResolver, () => DateTime.UtcNow)
 {
 }
Пример #5
0
 public BackgroundJobPerformer(
     [NotNull] IJobFilterProvider filterProvider,
     [NotNull] JobActivator activator,
     [CanBeNull] TaskScheduler taskScheduler)
     : this(filterProvider, new CoreBackgroundJobPerformer(activator, taskScheduler))
 {
 }
Пример #6
0
 public RecurringJobManager(
     [NotNull] JobStorage storage,
     [NotNull] IJobFilterProvider filterProvider,
     [NotNull] ITimeZoneResolver timeZoneResolver,
     [NotNull] Func <DateTime> nowFactory)
     : this(storage, new BackgroundJobFactory(filterProvider), timeZoneResolver, nowFactory)
 {
 }
Пример #7
0
        internal BackgroundJobStateChanger([NotNull] IJobFilterProvider filterProvider, [NotNull] IStateMachine stateMachine)
        {
            if (stateMachine == null)
            {
                throw new ArgumentNullException(nameof(stateMachine));
            }

            _stateMachine = new StateMachine(filterProvider, stateMachine);
        }
Пример #8
0
        internal BackgroundJobPerformer(
            [NotNull] IJobFilterProvider filterProvider, 
            [NotNull] IBackgroundJobPerformer innerPerformer)
        {
            if (filterProvider == null) throw new ArgumentNullException(nameof(filterProvider));
            if (innerPerformer == null) throw new ArgumentNullException(nameof(innerPerformer));

            _filterProvider = filterProvider;
            _innerPerformer = innerPerformer;
        }
Пример #9
0
 internal StateMachine(
     [NotNull] IJobFilterProvider filterProvider, 
     [NotNull] IStateMachine innerStateMachine)
 {
     if (filterProvider == null) throw new ArgumentNullException(nameof(filterProvider));
     if (innerStateMachine == null) throw new ArgumentNullException(nameof(innerStateMachine));
     
     _filterProvider = filterProvider;
     _innerStateMachine = innerStateMachine;
 }
Пример #10
0
        internal BackgroundJobFactory(
            [NotNull] IJobFilterProvider filterProvider, 
            [NotNull] IBackgroundJobFactory innerFactory)
        {
            if (filterProvider == null) throw new ArgumentNullException(nameof(filterProvider));
            if (innerFactory == null) throw new ArgumentNullException(nameof(innerFactory));

            _filterProvider = filterProvider;
            _innerFactory = innerFactory;
        }
Пример #11
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());
        }
        public AsyncBackgroundJobPerformer([NotNull] IJobFilterProvider filterProvider, [NotNull] IAsyncBackgroundJobPerformer innerPerformer)
        {
            if (filterProvider == null)
            {
                throw new ArgumentNullException(nameof(filterProvider));
            }
            if (innerPerformer == null)
            {
                throw new ArgumentNullException(nameof(innerPerformer));
            }

            _filterProvider = filterProvider;
            _innerPerformer = innerPerformer;
        }
Пример #13
0
        public CoreBackgroundJobPerformer(
            [NotNull] JobActivator activator,
            [NotNull] IJobFilterProvider filterProvider)
        {
            if (activator == null)
            {
                throw new ArgumentNullException("activator");
            }
            if (filterProvider == null)
            {
                throw new ArgumentNullException("filterProvider");
            }

            _activator      = activator;
            _filterProvider = filterProvider;
        }
Пример #14
0
        internal BackgroundJobPerformer(
            [NotNull] IJobFilterProvider filterProvider,
            [NotNull] IBackgroundJobPerformer innerPerformer)
        {
            if (filterProvider == null)
            {
                throw new ArgumentNullException("filterProvider");
            }
            if (innerPerformer == null)
            {
                throw new ArgumentNullException("innerPerformer");
            }

            _filterProvider = filterProvider;
            _innerPerformer = innerPerformer;
        }
Пример #15
0
        internal BackgroundJobFactory(
            [NotNull] IJobFilterProvider filterProvider,
            [NotNull] IBackgroundJobFactory innerFactory)
        {
            if (filterProvider == null)
            {
                throw new ArgumentNullException(nameof(filterProvider));
            }
            if (innerFactory == null)
            {
                throw new ArgumentNullException(nameof(innerFactory));
            }

            _filterProvider = filterProvider;
            _innerFactory   = innerFactory;
        }
Пример #16
0
        internal StateMachine(
            [NotNull] IJobFilterProvider filterProvider,
            [NotNull] IStateMachine innerStateMachine)
        {
            if (filterProvider == null)
            {
                throw new ArgumentNullException(nameof(filterProvider));
            }
            if (innerStateMachine == null)
            {
                throw new ArgumentNullException(nameof(innerStateMachine));
            }

            _filterProvider    = filterProvider;
            _innerStateMachine = innerStateMachine;
        }
Пример #17
0
        public static (BackgroundJobServer server, IRecurringJobManager recurringJobManager, IBackgroundJobClient backgroundJobClient) StartHangfireServer(
            BackgroundJobServerOptions options,
            string connectionString,
            IApplicationLifetime applicationLifetime,
            IJobFilterProvider jobFilters,
            JobActivator jobActivator,
            IBackgroundJobFactory backgroundJobFactory,
            IBackgroundJobPerformer backgroundJobPerformer,
            IBackgroundJobStateChanger backgroundJobStateChanger,
            IBackgroundProcess[] additionalProcesses
            )
        {
            JobStorage storage;

            if (string.IsNullOrWhiteSpace(connectionString))
            {
                storage = new MemoryStorage();
            }
            else if (ConnectionStringHelper.IsSQLite(connectionString))
            {
                storage = new SQLiteStorage(connectionString);
            }
            else
            {
                storage = new SqlServerStorage(connectionString);
            }

            var server = new BackgroundJobServer(options, storage, additionalProcesses,
                                                 options.FilterProvider ?? jobFilters,
                                                 options.Activator ?? jobActivator,
                                                 backgroundJobFactory,
                                                 backgroundJobPerformer,
                                                 backgroundJobStateChanger);

            applicationLifetime.ApplicationStopping.Register(() => server.SendStop());
            applicationLifetime.ApplicationStopped.Register(() => server.Dispose());

            var recurringJobManager = new RecurringJobManager(storage, backgroundJobFactory);

            var backgroundJobClient = new BackgroundJobClient(storage, backgroundJobFactory, backgroundJobStateChanger);

            return(server, recurringJobManager, backgroundJobClient);
        }
Пример #18
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);
        }
Пример #19
0
        public HangfireServer(
            BackgroundJobServerOptions options,
            JobStorage jobStorage,
            IEnumerable <IBackgroundProcess> backgroundProcesses,
            IBackgroundJobFactory jobFactory,
            IBackgroundJobPerformer jobPerformer,
            IBackgroundJobStateChanger jobStateChanger,
            ILogger <HangfireServer> logger,
            IJobFilterProvider jobFilterProvider = default,
            JobActivator activator = default
            )
        {
            _options             = options;
            _jobStorage          = jobStorage;
            _backgroundProcesses = backgroundProcesses;
            _jobFactory          = jobFactory;
            _jobPerformer        = jobPerformer;
            _jobStateChanger     = jobStateChanger;
            _jobFilterProvider   = options.FilterProvider ?? jobFilterProvider;
            _activator           = options.Activator ?? activator;

            _logger = logger;
        }
Пример #20
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);
        }
Пример #21
0
 public BackgroundJobClientWithContext([NotNull] JobStorage storage, [NotNull] IJobFilterProvider filterProvider)
     : this(storage, new BackgroundJobFactory(filterProvider), new BackgroundJobStateChanger(filterProvider))
 {
 }
Пример #22
0
 public StateMachine([NotNull] IJobFilterProvider filterProvider)
     : this(filterProvider, new CoreStateMachine())
 {
 }
Пример #23
0
 public RecurringJobManager([NotNull] JobStorage storage, [NotNull] IJobFilterProvider filterProvider)
     : this(storage, filterProvider, new DefaultTimeZoneResolver())
 {
 }
Пример #24
0
 public BackgroundJobStateChanger([NotNull] IJobFilterProvider filterProvider)
     : this(filterProvider, new CoreStateMachine())
 {
 }
 public SpecifyQueueBackgroundJobClient([NotNull] JobStorage storage, [NotNull] IJobFilterProvider filterProvider)
     : this(storage, new BackgroundJobFactory(filterProvider), new BackgroundJobStateChanger(filterProvider))
 {
 }
Пример #26
0
 public BackgroundJobPerformer(
     [NotNull] IJobFilterProvider filterProvider,
     [NotNull] JobActivator activator)
     : this(filterProvider, new CoreBackgroundJobPerformer(activator, filterProvider))
 {
 }
Пример #27
0
 public BackgroundJobFactory([NotNull] IJobFilterProvider filterProvider)
     : this(filterProvider, new CoreBackgroundJobFactory(new StateMachine(filterProvider)))
 {
 }
Пример #28
0
 public BackgroundJobPerformer([NotNull] IJobFilterProvider filterProvider)
     : this(filterProvider, new CoreBackgroundJobPerformer())
 {
 }
Пример #29
0
 public BackgroundJobPerformer([NotNull] IJobFilterProvider filterProvider)
     : this(filterProvider, JobActivator.Current)
 {
 }
Пример #30
0
 public BackgroundJobPerformer(
     [NotNull] IJobFilterProvider filterProvider,
     [NotNull] JobActivator activator)
     : this(filterProvider, activator, TaskScheduler.Default)
 {
 }