Ejemplo n.º 1
0
        public IBackgroundDispatcher Create(BackgroundServerContext context, BackgroundProcessingServerOptions options)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            var execution = new BackgroundExecution(
                context.StoppingToken,
                new BackgroundExecutionOptions
            {
                Name       = _process.GetType().Name,
                RetryDelay = options.RetryDelay
            });

            return(new BackgroundDispatcherAsync(
                       execution,
                       ExecuteProcess,
                       Tuple.Create(_process, context, execution),
                       _taskScheduler(),
                       _maxConcurrency,
                       _ownsScheduler));
        }
Ejemplo n.º 2
0
 public BackgroundProcessingServer(
     [NotNull] JobStorage storage,
     [NotNull] IEnumerable <IBackgroundProcessDispatcherBuilder> dispatcherBuilders,
     [NotNull] IDictionary <string, object> properties,
     [NotNull] BackgroundProcessingServerOptions options)
     : this(new BackgroundServerProcess(storage, dispatcherBuilders, options, properties), options)
 {
 }
Ejemplo n.º 3
0
 public BackgroundProcessingServer(
     [NotNull] JobStorage storage,
     [NotNull] IEnumerable <IBackgroundProcess> processes,
     [NotNull] IDictionary <string, object> properties,
     [NotNull] BackgroundProcessingServerOptions options)
     : this(storage, GetProcesses(processes), properties, options)
 {
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BackgroundProcessingServer"/>
        /// class and immediately starts all the given background processes.
        /// </summary>
        internal BackgroundProcessingServer(
            [NotNull] BackgroundServerProcess process,
            [NotNull] BackgroundProcessingServerOptions options)
        {
            _process = process ?? throw new ArgumentNullException(nameof(process));
            _options = options ?? throw new ArgumentNullException(nameof(options));

            _dispatcher = CreateDispatcher();

#if !NETSTANDARD1_3
            AppDomain.CurrentDomain.DomainUnload += OnCurrentDomainUnload;
            AppDomain.CurrentDomain.ProcessExit  += OnCurrentDomainUnload;
#endif
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BackgroundProcessingServer"/>
        /// class and immediately starts all the given background processes.
        /// </summary>
        internal BackgroundProcessingServer(
            [NotNull] BackgroundServerProcess process,
            [NotNull] BackgroundProcessingServerOptions options)
        {
            _process = process ?? throw new ArgumentNullException(nameof(process));
            _options = options ?? throw new ArgumentNullException(nameof(options));

            _dispatcher = CreateDispatcher();

#if !NETSTANDARD1_3
            AppDomain.CurrentDomain.DomainUnload += OnCurrentDomainUnload;
            AppDomain.CurrentDomain.ProcessExit  += OnCurrentDomainUnload;
#endif

            _shutdownRegistration = AspNetShutdownDetector.GetShutdownToken().Register(Dispose);
        }
        public IBackgroundDispatcher Create(BackgroundServerContext context, BackgroundProcessingServerOptions options)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            return(new BackgroundDispatcher(
                       new BackgroundExecution(context.StoppingToken, new BackgroundExecutionOptions
            {
                Name = _component.GetType().Name,
                RetryDelay = options.RetryDelay
            }),
                       ExecuteComponent,
                       Tuple.Create(_component, context),
                       _threadFactory));
        }
        public BackgroundServerProcess(
            [NotNull] JobStorage storage,
            [NotNull] IEnumerable <IBackgroundProcessDispatcherBuilder> dispatcherBuilders,
            [NotNull] BackgroundProcessingServerOptions options,
            [NotNull] IDictionary <string, object> properties)
        {
            if (dispatcherBuilders == null)
            {
                throw new ArgumentNullException(nameof(dispatcherBuilders));
            }

            _storage    = storage ?? throw new ArgumentNullException(nameof(storage));
            _options    = options ?? throw new ArgumentNullException(nameof(options));
            _properties = properties ?? throw new ArgumentNullException(nameof(properties));

            var builders = new List <IBackgroundProcessDispatcherBuilder>();

            builders.AddRange(GetRequiredProcesses());
            builders.AddRange(GetStorageComponents());
            builders.AddRange(dispatcherBuilders);

            _dispatcherBuilders = builders.ToArray();
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BackgroundProcessingServer"/>
        /// class and immediately starts all the given background processes.
        /// </summary>
        /// <param name="storage"></param>
        /// <param name="processes"></param>
        /// <param name="properties"></param>
        /// <param name="options"></param>
        public BackgroundProcessingServer(
            [NotNull] JobStorage storage,
            [NotNull] IEnumerable <IBackgroundProcess> processes,
            [NotNull] IDictionary <string, object> properties,
            [NotNull] BackgroundProcessingServerOptions options)
        {
            if (storage == null)
            {
                throw new ArgumentNullException(nameof(storage));
            }
            if (processes == null)
            {
                throw new ArgumentNullException(nameof(processes));
            }
            if (properties == null)
            {
                throw new ArgumentNullException(nameof(properties));
            }
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            _options = options;

            _processes.AddRange(GetRequiredProcesses());
            _processes.AddRange(storage.GetComponents());
            _processes.AddRange(processes);

            var context = new BackgroundProcessContext(
                GetGloballyUniqueServerId(),
                storage,
                properties,
                _cts.Token);

            _bootstrapTask = WrapProcess(this).CreateTask(context);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="BackgroundProcessingServer"/>
        /// class and immediately starts all the given background processes.
        /// </summary>
        /// <param name="storage"></param>
        /// <param name="processes"></param>
        /// <param name="properties"></param>
        /// <param name="options"></param>
        public BackgroundProcessingServer(
            [NotNull] JobStorage storage, 
            [NotNull] IEnumerable<IBackgroundProcess> processes,
            [NotNull] IDictionary<string, object> properties, 
            [NotNull] BackgroundProcessingServerOptions options)
        {
            if (storage == null) throw new ArgumentNullException(nameof(storage));
            if (processes == null) throw new ArgumentNullException(nameof(processes));
            if (properties == null) throw new ArgumentNullException(nameof(properties));
            if (options == null) throw new ArgumentNullException(nameof(options));

            _options = options;

            _processes.AddRange(GetRequiredProcesses());
            _processes.AddRange(storage.GetComponents());
            _processes.AddRange(processes);

            var context = new BackgroundProcessContext(
                GetGloballyUniqueServerId(), 
                storage,
                properties,
                _cts.Token);

            _bootstrapTask = WrapProcess(this).CreateTask(context);
        }