【发布时间】:2021-07-10 21:20:25
【问题描述】:
目标: 我想在提交数据后提交用户详细信息需要异步发送2条短信给用户。
问题:
-
IJobExecutionContext 值被最后调用的方法替换 - 例子
smsaftersubmit(userId, vehiId, "Booking");- 此方法替换为最后一个方法,即smsaftersubmit(userId, vehiId, cusId, "Coonfirmation"); -
我创建了异步石英作业,如果我使用 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);
}
}
我是石英调度的新手,请帮我解决这个问题..
【问题讨论】:
标签: c# entity-framework model-view-controller quartz.net