Esempio n. 1
0
        public BackgroundTaskHost(
            IServiceProvider backgroundServices,
            IBackgroundTaskStore store,
            IBackgroundTaskSerializer serializer,
            ITypeResolver typeResolver,
            IOptionsMonitor <BackgroundTaskOptions> options,
            ISafeLogger <BackgroundTaskHost> logger)
        {
            _backgroundServices = backgroundServices;
            Store         = store;
            Serializer    = serializer;
            _typeResolver = typeResolver;
            _options      = options;
            _logger       = logger;
            options.OnChange(OnSettingsChanged);

            _schedulers = new ConcurrentDictionary <int, TaskScheduler>();
            _factories  = new ConcurrentDictionary <TaskScheduler, TaskFactory>();
            _pending    = new ConcurrentDictionary <object, HandlerHooks>();
            _cancel     = new CancellationTokenSource();

            // dispatch thread
            _background = new PushQueue <IEnumerable <BackgroundTask> >();
            _background.Attach(WithPendingTasks);
            _background.AttachBacklog(WithOverflowTasks);
            _background.AttachUndeliverable(WithFailedTasks);

            // maintenance thread
            _maintenance = new PushQueue <IEnumerable <BackgroundTask> >();
            _maintenance.Attach(WithHangingTasks);
            _maintenance.AttachBacklog(WithHangingTasks);
            _maintenance.AttachUndeliverable(WithFailedTasks);
        }
Esempio n. 2
0
 public BackgroundTaskController(IBackgroundTaskStore store, ITypeResolver typeResolver, BackgroundTaskHost host,
                                 IOptionsMonitor <BackgroundTaskOptions> options)
 {
     _store        = store;
     _typeResolver = typeResolver;
     _host         = host;
     _options      = options;
 }
Esempio n. 3
0
        public bool IsRunningOvertime(IBackgroundTaskStore store)
        {
            if (!LockedAt.HasValue)
            {
                return(false);
            }

            if (!MaximumRuntime.HasValue)
            {
                return(false);
            }

            var now     = store.GetTaskTimestamp();
            var elapsed = now - LockedAt.Value;

            // overtime = 125% of maximum runtime
            var overage  = TimeSpan.FromTicks((long)(MaximumRuntime.Value.Ticks * 0.25f));
            var overtime = MaximumRuntime.Value + overage;

            return(elapsed >= overtime);
        }
Esempio n. 4
0
 protected BackgroundTaskStoreTests(IServiceProvider serviceProvider) : base(serviceProvider)
 {
     Store = ServiceProvider.GetRequiredService(typeof(IBackgroundTaskStore)) as IBackgroundTaskStore;
 }
Esempio n. 5
0
 protected BackgroundTaskHostTests(IServiceProvider serviceProvider, ITestOutputHelper console) : base(serviceProvider)
 {
     _console = console;
     Store    = ServiceProvider.GetRequiredService(typeof(IBackgroundTaskStore)) as IBackgroundTaskStore;
 }