Esempio n. 1
0
        public async Task <IActionResult> CreateMinutelyBackgroundTask([FromBody] CreateBackgroundTaskModel model,
                                                                       [FromRoute] int minutes = 0, [FromRoute] int atSecond = 0)
        {
            model.Expression = CronTemplates.Minutely(minutes, atSecond);

            return(await CreateBackgroundTask(model));
        }
Esempio n. 2
0
        public void Every_n_minutes(int n)
        {
            var cron     = CronTemplates.Minutely(n);
            var schedule = CronTemplates.Parse(cron);
            var diff     = CompareTwoCronOccurrences(schedule);

            Assert.Equal(n, diff.Minutes);
        }
Esempio n. 3
0
        public void Queues_for_delayed_execution_and_continous_repeating_task()
        {
            using (var db = new SqlServerFixture())
            {
                MigrationHelper.MigrateToLatest("sqlserver", db.ConnectionString);

                ScheduledProducerSettings settings = new ScheduledProducerSettings
                {
                    DelayTasks    = true,
                    Concurrency   = 0,
                    SleepInterval = TimeSpan.FromSeconds(1),
                    Store         = new SqlScheduleStore(db.ConnectionString)
                };

                ScheduledProducer scheduler = new ScheduledProducer(settings);
                scheduler.ScheduleAsync <StaticCountingHandler>(o => o.RepeatIndefinitely(CronTemplates.Minutely()));
                scheduler.Start(); // <-- starts background thread to poll for tasks

                Assert.True(StaticCountingHandler.Count == 0, "handler should not have queued immediately since tasks are delayed");
                Thread.Sleep(TimeSpan.FromMinutes(1.1)); // <-- enough time for the next occurrence
                Assert.True(StaticCountingHandler.Count > 0, "handler should have executed since we scheduled it in the future");
                Assert.Equal(2, StaticCountingHandler.Count);
            }
        }