0

I've setup a chrono Job using Quartz library for .NET. Basically, I want a job scheduled every hour and every day at a specific minute (i.e. 10). This is done simply with this chrono expression 0 10 * ? * * *, but how can I achieve the following behavior?:

  • if the program at XX:12, then run it immediately
  • if the program is started before XX:10, then wait for the chrono scheduler

I've tried this solution but It does not work.

  q.AddTrigger(opts =>
          opts.ForJob(job)
              .WithIdentity("CalcServiceJob-trigger")
              .StartNow()
              .WithCronSchedule("0 10 * ? * * *")
      );

I've also tried this configuration without relevant results

q.AddTrigger(opts =>
          opts.ForJob(job)
              .WithIdentity("CalcServiceJob-trigger")
              .WithCronSchedule("0 10 * ? * * *", x => x.WithMisfireHandlingInstructionFireAndProceed())
      );
alex
  • 380
  • 3
  • 8

1 Answers1

0

You can add another trigger that fires immediately and only once against the job:

q.AddTrigger(t => t
    .ForJob(job)
    .StartNow()
    .WithSimpleSchedule(x => x.WithRepeatCount(0).WithInterval(TimeSpan.Zero))
);
Marko Lahma
  • 6,586
  • 25
  • 29
  • This solution works even if the program is started before XX:10. Instead I would like this behavior: - if the program is started before XX:10, wait for the chrono scheduler - if the program is started after XX:10, then starts immediately. – alex Dec 15 '22 at 10:06
  • Maybe you can write if clause around the registration? – Marko Lahma Dec 16 '22 at 11:17