1

I have a C# Topshelf windows Service that processes Quartz Jobs. Those jobs are stored in the database, like this:

public class JobConfiguration : IJobConfiguration {   
   public string Name { get; set; }          //ImportService
   public string Type { get; set; }          //[ClassName, AssemblyName]
   public string CronTrigger { get; set; }   //example: 0 0 12 * * ? 
   public string CronMeaning { get; set; }   //example: fire at noon every day
} 

Now I have to add a Job that is only fired once (all other jobs had to be repeated). My (temporary) solution is to leave the CronTrigger field NULL and start those jobs with a SimpleTrigger instead of a CronTrigger like:

if (JobConfiguration.CronTrigger == Null)
   //start job with Quartz SimpleTrigger
else
   //start job with Quartz CronTrigger

Is there a better solution to do this? In other words: is there a CronTrigger that allows you to start a job only once and never repeat it.

M.Babcock
  • 18,753
  • 6
  • 54
  • 84
yoerids
  • 918
  • 1
  • 8
  • 19

1 Answers1

2

One solution would be to make the JobConfiguration abstract and have a SimpleJobConfiguration and CronJobConfiguration inherit from that JobConfiguration.

In the database they can be stored in the same table.

An other solution is to use the StartTimeUtc and EndTimeUtc of a trigger, both Simple and Cron. This allows you to create a cron statement that will run every 30 minutes but with an EndDateUtc on the trigger of DateTime.Now().Add(TimeSpan.FromMinutes(31)).

Jochen
  • 1,488
  • 16
  • 21