Esempio n. 1
0
        public async Task <IActionResult> Edit(BackgroundTaskViewModel model)
        {
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageBackgroundTasks))
            {
                return(Forbid());
            }

            if (ModelState.IsValid)
            {
                if (String.IsNullOrWhiteSpace(model.Name))
                {
                    ModelState.AddModelError(nameof(BackgroundTaskViewModel.Name), S["The name is mandatory."]);
                }
            }

            if (ModelState.IsValid)
            {
                var settings = new BackgroundTaskSettings
                {
                    Name        = model.Name,
                    Enable      = model.Enable,
                    Schedule    = model.Schedule?.Trim(),
                    Description = model.Description
                };

                await _backgroundTaskManager.UpdateAsync(model.Name, settings);

                return(RedirectToAction(nameof(Index)));
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Esempio n. 2
0
        public async Task UpdateAsync(string name, BackgroundTaskSettings settings)
        {
            var document = await LoadDocumentAsync();

            document.Settings[name] = settings;
            await _documentManager.UpdateAsync(document);
        }
Esempio n. 3
0
 public TvMazeScrapperService(IOptions <BackgroundTaskSettings> settings,
                              ILogger <TvMazeScrapperService> logger,
                              TvMazeUpdater updater)
 {
     this._settings = settings?.Value ?? throw new ArgumentNullException(paramName: nameof(settings));
     this._logger   = logger ?? throw new ArgumentNullException(paramName: nameof(logger));
     this._updater  = updater ?? throw new ArgumentNullException(paramName: nameof(updater));
 }
 public GracePeriodManagerService(IOptions <BackgroundTaskSettings> settings,
                                  IEventBus eventBus,
                                  ILogger <GracePeriodManagerService> logger)
 {
     _settings = settings?.Value ?? throw new ArgumentNullException(nameof(settings));
     _eventBus = eventBus ?? throw new ArgumentNullException(nameof(eventBus));
     _logger   = logger ?? throw new ArgumentNullException(nameof(logger));
 }
Esempio n. 5
0
        public ProcessorService(IOptions <BackgroundTaskSettings> settings, ILogger <ProcessorService> logger, IServiceScopeFactory serviceScopeFactory, AtlasService atlasService)
        {
            _settings            = settings?.Value ?? throw new ArgumentNullException(nameof(settings));
            _logger              = logger ?? throw new ArgumentNullException(nameof(logger));
            _serviceScopeFactory = serviceScopeFactory;

            _atlasService = atlasService ?? throw new ArgumentNullException(nameof(atlasService));
        }
Esempio n. 6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EmailNotificationConsumerBackgroundService"/>
 /// </summary>
 /// <param name="logger">The logger.</param>
 /// <param name="backgroundTaskSettingsOptions">The background settings options.</param>
 /// <param name="serviceProvider">The service provider.</param>
 public EmailNotificationConsumerBackgroundService(
     ILogger <EmailNotificationConsumerBackgroundService> logger,
     IOptions <BackgroundTaskSettings> backgroundTaskSettingsOptions,
     IServiceProvider serviceProvider)
 {
     _logger                 = logger;
     _serviceProvider        = serviceProvider;
     _backgroundTaskSettings = backgroundTaskSettingsOptions.Value;
 }
Esempio n. 7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GroupEventNotificationsProducerBackgroundService"/> class.
 /// </summary>
 /// <param name="logger">The logger.</param>
 /// <param name="backgroundTaskSettingsOptions">The background task settings options.</param>
 /// <param name="serviceProvider">The service provider.</param>
 public GroupEventNotificationsProducerBackgroundService(
     ILogger <GroupEventNotificationsProducerBackgroundService> logger,
     IOptions <BackgroundTaskSettings> backgroundTaskSettingsOptions,
     IServiceProvider serviceProvider)
 {
     _logger = logger;
     _backgroundTaskSettings = backgroundTaskSettingsOptions.Value;
     _serviceProvider        = serviceProvider;
 }
Esempio n. 8
0
 public GeolocationManagerTask(
     IOptions <BackgroundTaskSettings> settings,
     IDriverRepository driverRepository,
     IMapper mapper)
 {
     _settings         = settings?.Value ?? throw new ArgumentNullException(nameof(settings));
     _driverRepository = driverRepository ?? throw new ArgumentNullException(nameof(driverRepository));
     _mapper           = mapper ?? throw new ArgumentNullException(nameof(mapper));
     _client           = new HttpClient();
 }
Esempio n. 9
0
 public TvMazeUpdater(ILogger <TvMazeScrapperService> logger,
                      IConcurrencyRepository repository,
                      IOptions <BackgroundTaskSettings> settings,
                      IEventBus eventBus)
 {
     this._logger     = logger ?? throw new ArgumentNullException(paramName: nameof(logger));
     this._repository = repository ?? throw new ArgumentNullException(paramName: nameof(repository));
     this._settings   = settings?.Value ?? throw new ArgumentNullException(paramName: nameof(settings));
     this._eventBus   = eventBus ?? throw new ArgumentNullException(paramName: nameof(eventBus));
 }
        public async Task UpdateAsync(string name, BackgroundTaskSettings settings)
        {
            var document = await GetDocumentAsync();

            document.Settings[name] = settings;
            _session.Save(document);

            _signal.SignalToken(CacheKey);
            _memoryCache.Set(CacheKey, document, ChangeToken);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="RallySimulationBackgroundService"/> class.
 /// </summary>
 /// <param name="logger">The logger.</param>
 /// <param name="backgroundTaskSettingsOptions">The background task settings options.</param>
 /// <param name="serviceProvider">The service provider.</param>
 /// <param name="dateTime">The date and time.</param>
 public RallySimulationBackgroundService(
     ILogger <RallySimulationBackgroundService> logger,
     IOptions <BackgroundTaskSettings> backgroundTaskSettingsOptions,
     IServiceProvider serviceProvider,
     IDateTime dateTime)
 {
     _logger = logger;
     _backgroundTaskSettings = backgroundTaskSettingsOptions.Value;
     _serviceProvider        = serviceProvider;
     _dateTime = dateTime;
     _random   = new Random();
 }
Esempio n. 12
0
        public async Task UpdateAsync(string name, BackgroundTaskSettings settings)
        {
            if (settings.IsReadonly)
            {
                throw new ArgumentException("The object is read-only");
            }

            var document = await LoadDocumentAsync();

            document.Settings[name] = settings;

            _session.Save(document);
            _signal.DeferredSignalToken(CacheKey);
        }
Esempio n. 13
0
 public EmailNotificationService(IOptions <BackgroundTaskSettings> settings, IEventBus eventBus, ILogger <EmailNotificationService> logger)
 {
     _settings = settings?.Value ?? throw new ArgumentNullException(nameof(settings));
     _eventBus = eventBus ?? throw new ArgumentNullException(nameof(eventBus));
     _logger   = logger ?? throw new ArgumentNullException(nameof(logger));
 }
Esempio n. 14
0
        private async Task UpdateAsync(IEnumerable <ShellContext> previousShells, IEnumerable <ShellContext> runningShells, CancellationToken stoppingToken)
        {
            var referenceTime = DateTime.UtcNow;

            await GetShellsToUpdate(previousShells, runningShells).ForEachAsync(async shell =>
            {
                var tenant = shell.Settings.Name;

                if (stoppingToken.IsCancellationRequested)
                {
                    return;
                }

                _httpContextAccessor.HttpContext = shell.CreateHttpContext();

                var shellScope = await _shellHost.GetScopeAsync(shell.Settings);

                if (shellScope.ShellContext.Pipeline == null)
                {
                    return;
                }

                await shellScope.UsingAsync(async scope =>
                {
                    var tasks = scope.ServiceProvider.GetServices <IBackgroundTask>();

                    CleanSchedulers(tenant, tasks);

                    if (!tasks.Any())
                    {
                        return;
                    }

                    var settingsProvider = scope.ServiceProvider.GetService <IBackgroundTaskSettingsProvider>();

                    _changeTokens[tenant] = settingsProvider?.ChangeToken ?? NullChangeToken.Singleton;

                    foreach (var task in tasks)
                    {
                        var taskName = task.GetTaskName();

                        if (!_schedulers.TryGetValue(tenant + taskName, out var scheduler))
                        {
                            _schedulers[tenant + taskName] = scheduler = new BackgroundTaskScheduler(tenant, taskName, referenceTime);
                        }

                        if (!scheduler.Released && scheduler.Updated)
                        {
                            continue;
                        }

                        BackgroundTaskSettings settings = null;

                        try
                        {
                            if (settingsProvider != null)
                            {
                                settings = await settingsProvider.GetSettingsAsync(task);
                            }
                        }

                        catch (Exception e)
                        {
                            Logger.LogError(e, "Error while updating settings of background task '{TaskName}' on tenant '{TenantName}'.", taskName, tenant);
                        }

                        settings = settings ?? task.GetDefaultSettings();

                        if (scheduler.Released || !scheduler.Settings.Schedule.Equals(settings.Schedule))
                        {
                            scheduler.ReferenceTime = referenceTime;
                        }

                        scheduler.Settings = settings;
                        scheduler.Released = false;
                        scheduler.Updated  = true;
                    }
                });
            });
        }
Esempio n. 15
0
 public GracePeriodManagerService(IOptions <BackgroundTaskSettings> settings, IAssetService assetService, ILogger <GracePeriodManagerService> logger)
 {
     _settings     = settings?.Value ?? throw new ArgumentNullException(nameof(settings));
     _assetService = assetService ?? throw new ArgumentNullException(nameof(assetService));
     _logger       = logger ?? throw new ArgumentNullException(nameof(logger));
 }
Esempio n. 16
0
 public Worker(ILogger <Worker> logger, IOptions <BackgroundTaskSettings> settings)
 {
     _logger   = logger;
     _settings = settings?.Value;
 }
 public OrderPaymentService(ILogger <OrderPaymentService> logger, IOptions <BackgroundTaskSettings> settings, IEventBus eventBus)
 {
     _logger   = logger ?? throw new ArgumentNullException(nameof(logger));
     _eventBus = eventBus ?? throw new ArgumentNullException(nameof(eventBus));
     _settings = settings?.Value ?? throw new ArgumentNullException(nameof(settings));
 }
Esempio n. 18
0
        // TODO: Implement event bus to deliver reminders
        //private readonly IEventBus _eventBus;

        public ReminderTask(IOptions <BackgroundTaskSettings> settings, ILogger <ReminderTask> logger)
        {
            _settings = settings?.Value ?? throw new ArgumentNullException(nameof(settings));
            _logger   = logger ?? throw new ArgumentNullException(nameof(logger));
            //_eventBus = eventBus ?? throw new ArgumentNullException(nameof(eventBus));
        }
Esempio n. 19
0
 public TvMazeApi(BackgroundTaskSettings settings)
 {
     this._settings = settings ?? throw new ArgumentNullException(paramName: nameof(settings));
 }