I have two quartz.net job classes as shown below;
[DisallowConcurrentExecution]
public class MyJob : IJob
{
public async Task Execute(IJobExecutionContext context)
{
JobDataMap dataMap = context.JobDetail.JobDataMap;
IScheduler sched = (IScheduler)dataMap["sched"];
IJobDetail job = JobBuilder.Create<TestJob>()
.WithIdentity(new JobKey("tt1", "Download test"))
.StoreDurably()
.Build();
await sched.AddJob(job, true);
for (int i = 0; i < 25; i++)
{
job.JobDataMap["trans"] = "tr_" + i.ToString();
ITrigger trigger = TriggerBuilder
.Create()
.WithIdentity("trigger_" + i, "Download test")
.ForJob(job)
.WithSimpleSchedule(x => x.WithIntervalInSeconds(1).WithRepeatCount(0))
.Build();
await sched.ScheduleJob(trigger);
}
}
}
[DisallowConcurrentExecution]
public class TestJob : IJob
{
public async Task Execute(IJobExecutionContext context)
{
JobDataMap dataMap = context.JobDetail.JobDataMap;
string trans = (string)dataMap["trans"];
var message = $"Sample executed at {DateTime.Now.ToString("u")} by job : {context.JobDetail.Key.Name} and transaction: {trans} ";
Debug.WriteLine(message);
}
}
I schedule "MyJob" like so
IScheduler myscheduler = _scheduler;
IOptions<endPoints> objEndpoint = _ep;
IOptions<ConnString> dobjConf = _conf;
IJobDetail download_job = JobBuilder.Create<MyJob>()
.WithIdentity("UT Download", "Download")
.WithDescription("Downloading transactions")
.StoreDurably()
.Build();
download_job.JobDataMap["sched"] = myscheduler;
download_job.JobDataMap.Put("downloadJobMetadata", new downloadJobMetadata { o_endpoint = objEndpoint, o_conf = dobjConf });
await _scheduler.AddJob(download_job, true);
ITrigger ut_trigger_first = TriggerBuilder.Create()
.ForJob(download_job)
.WithIdentity("Download Trigger One", "Download")
.WithSimpleSchedule(x => x.WithIntervalInSeconds(20).RepeatForever())
.Build();
await _scheduler.ScheduleJob(ut_trigger_first);
Now, the output in console looks like so
Sample executed at 2022-09-24 22:04:15Z by job : tt1 and transaction:
Sample executed at 2022-09-24 22:04:15Z by job : tt1 and transaction:
Sample executed at 2022-09-24 22:04:15Z by job : tt1 and transaction:
Sample executed at 2022-09-24 22:04:15Z by job : tt1 and transaction:
Sample executed at 2022-09-24 22:04:15Z by job : tt1 and transaction:
Sample executed at 2022-09-24 22:04:15Z by job : tt1 and transaction:
Sample executed at 2022-09-24 22:04:15Z by job : tt1 and transaction:
Sample executed at 2022-09-24 22:04:15Z by job : tt1 and transaction:
Sample executed at 2022-09-24 22:04:15Z by job : tt1 and transaction:
Sample executed at 2022-09-24 22:04:15Z by job : tt1 and transaction:
Sample executed at 2022-09-24 22:04:15Z by job : tt1 and transaction:
Sample executed at 2022-09-24 22:04:15Z by job : tt1 and transaction:
Sample executed at 2022-09-24 22:04:15Z by job : tt1 and transaction:
Sample executed at 2022-09-24 22:04:15Z by job : tt1 and transaction:
Sample executed at 2022-09-24 22:04:15Z by job : tt1 and transaction:
Sample executed at 2022-09-24 22:04:15Z by job : tt1 and transaction:
Sample executed at 2022-09-24 22:04:15Z by job : tt1 and transaction:
Sample executed at 2022-09-24 22:04:15Z by job : tt1 and transaction:
Sample executed at 2022-09-24 22:04:15Z by job : tt1 and transaction:
Sample executed at 2022-09-24 22:04:15Z by job : tt1 and transaction:
Sample executed at 2022-09-24 22:04:15Z by job : tt1 and transaction:
Sample executed at 2022-09-24 22:04:15Z by job : tt1 and transaction:
Sample executed at 2022-09-24 22:04:15Z by job : tt1 and transaction:
Sample executed at 2022-09-24 22:04:15Z by job : tt1 and transaction:
Sample executed at 2022-09-24 22:04:15Z by job : tt1 and transaction:
But my desired out is
Sample executed at 2022-09-24 22:04:15Z by job : tt1 and transaction:tr_0
Sample executed at 2022-09-24 22:04:15Z by job : tt1 and transaction:tr_1
Sample executed at 2022-09-24 22:04:15Z by job : tt1 and transaction:tr_2
Sample executed at 2022-09-24 22:04:15Z by job : tt1 and transaction:tr_3
Sample executed at 2022-09-24 22:04:15Z by job : tt1 and transaction:tr_4
Sample executed at 2022-09-24 22:04:15Z by job : tt1 and transaction:tr_5
Sample executed at 2022-09-24 22:04:15Z by job : tt1 and transaction:tr_6
Sample executed at 2022-09-24 22:04:15Z by job : tt1 and transaction:tr_7
Sample executed at 2022-09-24 22:04:15Z by job : tt1 and transaction:tr_8
Sample executed at 2022-09-24 22:04:15Z by job : tt1 and transaction:tr_9
Sample executed at 2022-09-24 22:04:15Z by job : tt1 and transaction:tr_10
Sample executed at 2022-09-24 22:04:15Z by job : tt1 and transaction:tr_11
Sample executed at 2022-09-24 22:04:15Z by job : tt1 and transaction:tr_12
Sample executed at 2022-09-24 22:04:15Z by job : tt1 and transaction:tr_13
Sample executed at 2022-09-24 22:04:15Z by job : tt1 and transaction:tr_14
Sample executed at 2022-09-24 22:04:15Z by job : tt1 and transaction:tr_15
Sample executed at 2022-09-24 22:04:15Z by job : tt1 and transaction:tr_16
Sample executed at 2022-09-24 22:04:15Z by job : tt1 and transaction:tr_17
Sample executed at 2022-09-24 22:04:15Z by job : tt1 and transaction:tr_18
Sample executed at 2022-09-24 22:04:15Z by job : tt1 and transaction:tr_19
Sample executed at 2022-09-24 22:04:15Z by job : tt1 and transaction:tr_20
Sample executed at 2022-09-24 22:04:15Z by job : tt1 and transaction:tr_21
Sample executed at 2022-09-24 22:04:15Z by job : tt1 and transaction:tr_22
Sample executed at 2022-09-24 22:04:15Z by job : tt1 and transaction:tr_23
Sample executed at 2022-09-24 22:04:15Z by job : tt1 and transaction:tr_24
Anything am not doing right?