C
C#6mo ago
engineertdog

Persist data between Quartz Execution

I need to be able to persist data between instance executions. I have to tie two separate jobs together through a common identifier. The approach below does not work. From my understanding, I will need to create a new schedule based off the old one in order to persist data?
c#
public virtual async Task Execute(IJobExecutionContext context) {
JobDataMap dataMap = context.MergedJobDataMap;
long count = dataMap.GetLong("jobIterationNumber");
count++;
dataMap.Put("jobIterationNumber", count);
Execute();

// Instead, build a new schedule based on the old one?
var oldMap = oldTrigger.JobDataMap;
oldMap["jobIterationNumber"] = count;

var oldTrigger = context.Trigger;
var newTrigger = TriggerBuilder.Create()
.WithIdentity(oldTrigger.Key.Name, oldTrigger.Key.Group)
.UsingJobData(oldTrigger.JobDataMap)
.WithSchedule(oldTrigger.GetScheduleBuilder())
.Build();
await context.Scheduler.ScheduleJob(newTrigger);
}
c#
public virtual async Task Execute(IJobExecutionContext context) {
JobDataMap dataMap = context.MergedJobDataMap;
long count = dataMap.GetLong("jobIterationNumber");
count++;
dataMap.Put("jobIterationNumber", count);
Execute();

// Instead, build a new schedule based on the old one?
var oldMap = oldTrigger.JobDataMap;
oldMap["jobIterationNumber"] = count;

var oldTrigger = context.Trigger;
var newTrigger = TriggerBuilder.Create()
.WithIdentity(oldTrigger.Key.Name, oldTrigger.Key.Group)
.UsingJobData(oldTrigger.JobDataMap)
.WithSchedule(oldTrigger.GetScheduleBuilder())
.Build();
await context.Scheduler.ScheduleJob(newTrigger);
}
0 Replies
No replies yetBe the first to reply to this messageJoin