Quartz.net不会解雇工作

时间:2013-11-28 18:08:00

标签: asp.net-mvc-4 quartz.net azure-worker-roles

我创建了两个工作角色的工作,用于发送群发邮件,一个计划在午夜后运行五分钟,另一个用于每小时运行以编写新的工作。

午夜Job CronTrigger的表达式是“0 5 0 * ?”而且每小时工作是“0 0 0/1 * ?”。

但是我在Azure中部署了worker角色,并且由于一个未知的原因,在我只有午夜工作并完成工作之前没有执行作业,但是实现了每小时的Job并且一切都停止了工作

以下是代码:

IJobDetail recordatorioJob = null;

CronScheduleBuilder cronTrigger = CronScheduleBuilder.CronSchedule("0 5 0 * * ?")
      .InTimeZone(TimeZoneInfo.FindSystemTimeZoneById("SA Pacific Standard Time"));

ITrigger recordatorioTrigger = null;

CrearJobYTrigger(typeof(RecordatorioCitasJob), 
    "RecordatorioCitas", 
    "groupRecordatorios", 
    out recordatorioJob, 
    out recordatorioTrigger, 
    "Recordatorios citas a los pacientes", 
    cronTrigger);

_automatizador.ScheduleJob(recordatorioJob, recordatorioTrigger);
Trace.TraceInformation("Job Recordatorio programado");

IJobDetail actualizarJob = null;
ITrigger actualizarTrigger = null;
CronScheduleBuilder cronActualizar = CronScheduleBuilder
    .CronSchedule(string.Format("0 0 {0}/1 1/1 * ?", TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, TimeZoneInfo.FindSystemTimeZoneById("SA Pacific Standard Time")).AddHours(1).Hour))
    .InTimeZone(TimeZoneInfo.FindSystemTimeZoneById("SA Pacific Standard Time"));

CrearJobYTrigger(typeof(ActualizarJob),
        "ActualizarDatos",
        "groupActualizar",
        out actualizarJob,
        out actualizarTrigger,
        "Actualiza el listado de jobs dentro del scheduler",
        cronActualizar);

_automatizador.ScheduleJob(actualizarJob, actualizarTrigger);

private void CrearJobYTrigger(Type tipoJob, string nombre, string grupo, out IJobDetail datosJob, out ITrigger datosTrigger, string descripcion = null, IScheduleBuilder schedule = null, IEnumerable<dynamic> dataMap = null)
    {
    JobBuilder jobBuilder = JobBuilder.Create(tipoJob)
        .WithIdentity(string.Format("{0}_Job", nombre), grupo);

    if (!string.IsNullOrWhiteSpace(descripcion))
    {
        jobBuilder = jobBuilder.WithDescription(descripcion);
    }
    if (dataMap != null)
    {
        JobDataMap jobMap = new JobDataMap();
        foreach (dynamic item in dataMap)
        {
        jobMap.Add(item.NombreParametro as string, item.DatosParametro);
        }
        jobBuilder.SetJobData(jobMap);
    }

    datosJob = jobBuilder.Build();

    TriggerBuilder triggerBuilder = TriggerBuilder.Create()
        .WithIdentity(string.Format("{0}_Trigger", nombre), grupo)
        .StartNow();

    if (schedule != null)
    {
        triggerBuilder = triggerBuilder.WithSchedule(schedule);
    }

    datosTrigger = triggerBuilder.Build();
}

0 个答案:

没有答案