Example #1
0
        public void ToString_should_return_the_correct_string()
        {
            var instant   = Instant.FromUtc(2020, 01, 26, 22, 25, 00);
            var fakeClock = new FakeClock(instant);

            var sut = new ScheduledTaskBuilder(fakeClock);

            Assert.That(sut.WithJobData("blah").Now().CreateTask().ToString(), Is.EqualTo("now"));
            Assert.That(sut.WithJobData("blah").At(new DateTime(2020, 01, 24)).CreateTask().ToString(), Is.EqualTo("at|2020-01-24T00:00:00"));
            Assert.That(sut.WithJobData("blah").At("2020-01-24T00:00:00").CreateTask().ToString(), Is.EqualTo("at|2020-01-24T00:00:00"));
            Assert.That(sut.WithJobData("blah").Every(Lapse.Days(3)).CreateTask().ToString(), Is.EqualTo("every|3d"));
            Assert.That(sut.WithJobData("blah").Every(Lapse.Seconds(10), 5).CreateTask().ToString(), Is.EqualTo("every|10ss|x5"));
            Assert.That(sut.WithJobData("blah").After(Lapse.Hours(2)).CreateTask().ToString(), Is.EqualTo("after|2hh"));
            Assert.That(sut.WithJobData("blah").EveryStartingAt(Lapse.Days(3), "2020-01-24T09:30:00").CreateTask().ToString(), Is.EqualTo("everyStartingAt|3d|2020-01-24T09:30:00"));
            Assert.That(sut.WithJobData("blah").EveryStartingAt(Lapse.Days(3), DateTime.Parse("2020-01-24T09:30:00")).CreateTask().ToString(), Is.EqualTo("everyStartingAt|3d|2020-01-24T09:30:00"));
        }
Example #2
0
        public async Task StartAsync(CancellationToken cancellationToken)
        {
            // Add some tasks to the repository
            _taskRepository.AddScheduledTask(_taskBuilderFactory.CreateBuilder().WithJobData("* run task now!").Now());
            _taskRepository.AddScheduledTask(_taskBuilderFactory.CreateBuilder().WithJobData("* run task after 10 seconds").After(Lapse.Seconds(30)));
            _taskRepository.AddScheduledTask(_taskBuilderFactory.CreateBuilder().WithJobData("* run task at a specified DateTime").At(DateTime.UtcNow.AddSeconds(20)));
            _taskRepository.AddScheduledTask(_taskBuilderFactory.CreateBuilder().WithJobData("* run task every 5 seconds for 3 times").Every(Lapse.Seconds(5), 3));
            _taskRepository.AddScheduledTask(_taskBuilderFactory.CreateBuilder().WithJobData("* run task every 20 seconds starting at now + 1mm").EveryStartingAt(Lapse.Seconds(20), DateTime.UtcNow.AddMinutes(1)).CreateTask());

            var payload = new SpecificTaskPayload()
            {
                SomethingSpecific = "Bob"
            };

            _taskRepository.AddScheduledTask(_taskBuilderFactory.CreateBuilder().WithJobData(payload).Now().CreateTask());
        }