public async Task run_the_same_job_concurrently() { var cronJob = CronJobBuilder.With( startImmediately: true, cronExpression: CronExpression.EveryOneSecond, arguments: CommandArguments.CommandDurationInSeconds(5), skipIfAlreadyRunning: false ); var testResult = await new SchedulerBuilder() .WithCronJobs(cronJob) .StopWhen(tr => tr.Commands.Count(c => c.Executable == cronJob.Executable) > 1) .RunAsync(); testResult.ShouldSatisfyAllConditions( () => testResult.TimedOut.ShouldBeFalse(), () => testResult.Commands.Count(c => c.Executable == cronJob.Executable).ShouldBeGreaterThan(1) ); }
public async Task log_error_when_running_long() { var cronJob = CronJobBuilder.With( startImmediately: true, cronExpression: CronExpression.Never, arguments: CommandArguments.CommandDurationInSeconds(3), logErrorAfter: TimeSpan.FromSeconds(2) ); var testResult = await new SchedulerBuilder() .WithCronJobs(cronJob) .StopWhen(le => le.LogLevel == LogLevel.Error && le.Message == string.Format(Resources.JobIsRunningLongerThanExpectedError, cronJob.Name)) .RunAsync(); testResult.ShouldSatisfyAllConditions( () => testResult.TimedOut.ShouldBeFalse(), () => testResult.LogEntries.ShouldContain(le => le.LogLevel == LogLevel.Error && le.Message == string.Format(Resources.JobIsRunningLongerThanExpectedError, cronJob.Name)) ); }
public async Task skip_already_running_job() { var cronJob = CronJobBuilder.With( startImmediately: true, cronExpression: CronExpression.EveryOneSecond, arguments: CommandArguments.CommandDurationInSeconds(5), skipIfAlreadyRunning: true ); var testResult = await new SchedulerBuilder() .WithCronJobs(cronJob) .StopAfter(TimeSpan.FromSeconds(3)) .RunAsync(); testResult.Commands .Where(c => c.Executable == cronJob.Executable) .Count() .ShouldBe(1); }
public static CronJob With(Guid?id = null, string name = null, bool enabled = true, string executable = null, IEnumerable <string> arguments = null, string cronExpression = null, TimeSpan?logWarningAfter = null, TimeSpan?logErrorAfter = null, TimeSpan?timeout = null, bool startImmediately = false, bool skipIfAlreadyRunning = false, bool stopIfApplicationStopping = true) { return(new CronJob { Id = id ?? Guid.NewGuid(), Name = name ?? Guid.NewGuid().ToString(), Enabled = enabled, Executable = executable ?? Guid.NewGuid().ToString(), Arguments = arguments ?? CommandArguments.CommandDurationInSeconds(0), CronExpression = cronExpression ?? CronExpression.Never, LogWarningAfter = logWarningAfter, LogErrorAfter = logErrorAfter, Timeout = timeout, StartImmediately = startImmediately, SkipIfAlreadyRunning = skipIfAlreadyRunning, StopIfApplicationStopping = stopIfApplicationStopping }); }