Пример #1
0
 /// <summary>
 /// This method is actually a hangfire server.
 /// </summary>
 /// <param name="processes"></param>
 /// <param name="c"></param>
 private void HangfireServer(List <IBackgroundProcess> processes, CancellationToken c)
 {
     using (var server = new BackgroundProcessingServer(JobStorage.Current, processes, new Dictionary <string, object>(), _options))
     {
         while (c.IsCancellationRequested == false)
         {
             //TODO: should we put a thread sleep here?
         }
         ;
     }
 }
Пример #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());
        }
        public BackgroundJobServer(
            [NotNull] BackgroundJobServerOptions options,
            [NotNull] JobStorage storage,
            [NotNull] IEnumerable <IBackgroundProcess> additionalProcesses)
        {
            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 <IBackgroundProcess>();

            processes.AddRange(GetRequiredProcesses());
            processes.AddRange(additionalProcesses);

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

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

            storage.WriteOptionsToLog(Logger);

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

            _processingServer = new BackgroundProcessingServer(
                storage,
                processes,
                properties,
                GetProcessingServerOptions());
        }