Ejemplo n.º 1
0
        private static void registerTasks(IServiceCollection services, ScheduledTasksStorage storage)
        {
            foreach (var task in storage.Tasks)
            {
                services.TryAddTransient(task.TaskType);
            }

            services.AddHostedService <ScheduledTasksBackgroundService>();
        }
Ejemplo n.º 2
0
        private static void configTasks(IServiceCollection services, Action <ScheduledTasksStorage> options)
        {
            var storage = new ScheduledTasksStorage();

            options(storage);
            registerTasks(services, storage);
            addPingTask(services, storage);
            services.TryAddSingleton(Options.Create(storage));
        }
Ejemplo n.º 3
0
        private static void addPingTask(IServiceCollection services, ScheduledTasksStorage storage)
        {
            if (string.IsNullOrWhiteSpace(storage.SiteRootUrl))
            {
                return;
            }

            services.AddHttpClient <MySitePingClient>(client =>
            {
                client.BaseAddress = new Uri(storage.SiteRootUrl);
                client.DefaultRequestHeaders.ConnectionClose = true;
                client.DefaultRequestHeaders.Add("User-Agent", "DNTScheduler 1.0");
            });

            storage.AddScheduledTask <PingTask>(runAt: utcNow => utcNow.Second == 1);
            services.TryAddSingleton <PingTask>();
        }