在Quartz.net C#中设置重试计数

时间:2019-07-11 12:40:32

标签: c# quartz

我正在使用Quartz.Net创建作业计划程序。我想为作业失败设置重试计数,即,当作业失败时,它将重试到特定时间。我对设置该计数有些坚持。

下面是执行作业的代码。

如果执行失败或发生异常,如何在此处设置重试计数?

 public async Task Execute(IJobExecutionContext context)
    {
        try
        {
            _logger.LogInformation("Job Execution !");

            JobKey key = context.JobDetail.Key;

            JobDataMap dataMap = context.MergedJobDataMap;


            using (var client = new HttpClient())
            {
                //context.JobDetail.JobDataMap[]
                HttpResponseMessage response = new HttpResponseMessage();
                client.Timeout = TimeSpan.FromMilliseconds(1000);
                response = await client.GetAsync(dataMap["APIURL"].ToString());
                // var result = await client.GetStringAsync(dataMap.Values);

                if (response.IsSuccessStatusCode)
                {
                    //Succces: Notification Mail
                    Console.WriteLine("success");
                }
                else
                {
                    Console.WriteLine("fail");
                }

            }
        }
        catch (Exception e)
        {
            _logger.LogInformation("Exception arrise !" + e.Message);

            JobExecutionException ex = new JobExecutionException(e);
            ex.RefireImmediately = true;
            throw;
        }

    }

0 个答案:

没有答案