Reputation: 193
I have array of datetimes(about 5000 elements) and want to execute a job on each of these datetimes. Datetimes in array are custom ones, not periodical, so I cannot use CronTrigger and others. Is there a simple way to create a trigger which will fire on given times? Yes, I know that I can to start a new simple trigger(with one fire time, no repeation) each time after my job finished, but this way is not convenient for me.
Upvotes: 2
Views: 1610
Reputation: 91
You can customize the datetime for trigger.The simple trigger which will fire n times from your customize time
public class JobScheduler
{
public static void Start()
{
ISchedulerFactory sf = new StdSchedulerFactory();
IScheduler sched = sf.GetScheduler();
DateTime[] Jobtime = new DateTime[5]; //Array Have Job time
startDate[0] = new DateTime(2015, 6, 3, 16, 57, 0);
startDate[1] = new DateTime(2015, 6, 3, 16, 59, 0);
startDate[2] = new DateTime(2015, 6, 3, 17, 1, 0);
startDate[3] = new DateTime(2015, 6, 3, 17, 4, 0);
for (int i = 1; i < Jobtime.Count(); i++)
{
sched.Start();
string strjob = "job" + i.ToString();
string strgroup = "group" + i.ToString();
string strtigger = "trigger" + i.ToString();
IJobDetail job = JobBuilder.Create<EmailJob>()
.WithIdentity(strjob, strgroup)
.Build();
ISimpleTrigger trigger = (ISimpleTrigger)TriggerBuilder.Create()
.WithIdentity(strtigger, strgroup)
.StartAt(Jobtime[i])
.Build();
sched.ScheduleJob(job, trigger);
}
}
}
Upvotes: 0
Reputation: 6789
You can write your own trigger and use it to execute your job. If you're using v1.0 then you'll have to create a class that extends Trigger. Take a look at the docs for more details. If you're running v2.0 then you want to extend AbstractTrigger.
Upvotes: 2