Quartz Job Context 值被替换
Quartz Job Context value getting replaced
目标:
我想提交数据后提交用户详细信息需要异步发送2条短信给用户。
问题:
IJobExecutionContext 值正在被最后调用的方法替换 -
例子
smsaftersubmit(userId, vehiId, "Booking");
- 此方法已替换为最后一种方法,即 smsaftersubmit(userId, vehiId, cusId, "Coonfirmation");
我已经创建了异步 quartz 作业,如果我 运行 同时使用 2 个不同的浏览器作业,只有 1 个作业正在执行,其他作业被跳过。
//calling an job when i submit the user registration form.
public string DataSubmit()
{
smsaftersubmit(userId, vehiId, "Booking");
smsaftersubmit(userId, vehiId, cusId, "Coonfirmation");
}
public void smsaftersubmit(long id, long vehicleId, long custId, string smsType)
{
IScheduler autosmsScheduler = StdSchedulerFactory.GetDefaultScheduler().Result;
autosmsScheduler.Start();
IJobDetail jobDetail = JobBuilder.Create<autofiresms>().Build();
ITrigger trigger = TriggerBuilder.Create().WithIdentity("DispoAutoSMSTrigger", "DispoAutoSMSGroup")
.StartNow().WithSimpleSchedule().Build();
autosmsScheduler.Context.Put("id", id);
autosmsScheduler.Context.Put("vehicleId", vehicleId);
autosmsScheduler.Context.Put("smsType", smsType);
autosmsScheduler.ScheduleJob(jobDetail, trigger);
}
//IJOB -- autofiresms
public class AutoSMSJob : IJob
{
Logger logger = LogManager.GetLogger("apkRegLogger");
public async Task Execute(IJobExecutionContext context)
{
try
{
JobDataMap smsParameter = context.JobDetail.JobDataMap;
long id, vehicleId;
string smsType;
id = context.Scheduler.Context.GetLong("id");
vehicleId = context.Scheduler.Context.GetLong("vehicleId");
smsType = context.Scheduler.Context.GetString("smsType");
// fetching sms template and from mysql and passing it to an API
}
catch (Exception ex)
{
}
logger.Info("\n\n Code Ended: " + DateTime.Now);
}
}
我是石英调度的新手,请帮我解决这个问题..
您现在正在将值放入全局调度程序上下文。您应该改为使用作业或触发器上下文。对于您的用例,我相信将这些添加到触发级别(每个作业调用可以有不同的值)。
ITrigger trigger = TriggerBuilder.Create()
.WithIdentity("DispoAutoSMSTrigger", "DispoAutoSMSGroup")
.StartNow()
.WithSimpleSchedule()
.UsingJobData("id", id)
.UsingJobData("vehicleId", vehicleId)
.UsingJobData("smsType", smsType)
.Build();
目标: 我想提交数据后提交用户详细信息需要异步发送2条短信给用户。
问题:
IJobExecutionContext 值正在被最后调用的方法替换 - 例子
smsaftersubmit(userId, vehiId, "Booking");
- 此方法已替换为最后一种方法,即smsaftersubmit(userId, vehiId, cusId, "Coonfirmation");
我已经创建了异步 quartz 作业,如果我 运行 同时使用 2 个不同的浏览器作业,只有 1 个作业正在执行,其他作业被跳过。
//calling an job when i submit the user registration form.
public string DataSubmit()
{
smsaftersubmit(userId, vehiId, "Booking");
smsaftersubmit(userId, vehiId, cusId, "Coonfirmation");
}
public void smsaftersubmit(long id, long vehicleId, long custId, string smsType)
{
IScheduler autosmsScheduler = StdSchedulerFactory.GetDefaultScheduler().Result;
autosmsScheduler.Start();
IJobDetail jobDetail = JobBuilder.Create<autofiresms>().Build();
ITrigger trigger = TriggerBuilder.Create().WithIdentity("DispoAutoSMSTrigger", "DispoAutoSMSGroup")
.StartNow().WithSimpleSchedule().Build();
autosmsScheduler.Context.Put("id", id);
autosmsScheduler.Context.Put("vehicleId", vehicleId);
autosmsScheduler.Context.Put("smsType", smsType);
autosmsScheduler.ScheduleJob(jobDetail, trigger);
}
//IJOB -- autofiresms
public class AutoSMSJob : IJob
{
Logger logger = LogManager.GetLogger("apkRegLogger");
public async Task Execute(IJobExecutionContext context)
{
try
{
JobDataMap smsParameter = context.JobDetail.JobDataMap;
long id, vehicleId;
string smsType;
id = context.Scheduler.Context.GetLong("id");
vehicleId = context.Scheduler.Context.GetLong("vehicleId");
smsType = context.Scheduler.Context.GetString("smsType");
// fetching sms template and from mysql and passing it to an API
}
catch (Exception ex)
{
}
logger.Info("\n\n Code Ended: " + DateTime.Now);
}
}
我是石英调度的新手,请帮我解决这个问题..
您现在正在将值放入全局调度程序上下文。您应该改为使用作业或触发器上下文。对于您的用例,我相信将这些添加到触发级别(每个作业调用可以有不同的值)。
ITrigger trigger = TriggerBuilder.Create()
.WithIdentity("DispoAutoSMSTrigger", "DispoAutoSMSGroup")
.StartNow()
.WithSimpleSchedule()
.UsingJobData("id", id)
.UsingJobData("vehicleId", vehicleId)
.UsingJobData("smsType", smsType)
.Build();