Exemplo n.º 1
0
        public AsyncBackgroundJobServer(
            [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 <ITaskSource>();

            processes.AddRange(GetRequiredProcesses());
            processes.AddRange(additionalProcesses.Select(ExtensionMethods.Loop).Select(ExtensionMethods.Wrap));

            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 AsyncBackgroundProcessingServer(
                storage,
                processes,
                properties,
                GetProcessingServerOptions());
        }
Exemplo n.º 2
0
        public CustomBackgroundJobServer(
            [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 <IBackgroundProcessDispatcherBuilder>();

            processes.AddRange(GetRequiredProcesses());
            processes.AddRange(additionalProcesses.Select(x => x.UseBackgroundPool(1)));

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

            _logger.Info($"Starting Custom 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());
        }