首页 > 解决方案 > quartz.net 将 trigger_state 设置为 ERROR,不知道为什么

问题描述

我有石英坚持到 SQL 服务器。我的测试环境中没有这个,但现在我转移到生产环境中并且它正在发生。现在作业运行一次并导致触发器设置为 ERROR。我看不出有什么理由。我的工作看起来像这样......没有任何记录。知道为什么吗?

public class SendEmailsJob : IJob
{
   public Task Execute(IJobExecutionContext context)
    {
        IEmailRepo _emailService = new EmailRepo();
        IContactHistory _contactHistoryService = new ContactHistoryRepo();
        IPolicyRepo _policyService = new PolicyRepo();
        NLog.Logger _logger = Log.Instance;
        IUtility _utilityService = new UtilityRepo();

        const string DIRECT_WELCOME = "DirectWelcome";
        const string DIRECT_POST_WELCOME = "DirectPostWelcome";
        const string DIRECT_SIGN_NOPAY = "DirectSignNoPay";
        const string DIRECT_NOSIGN_NOPAY = "DirectNoSignNoPay";

        try
        {
            var templates = _utilityService.GetEmailTemplates();
            foreach (var template in templates)
            {
                if (template.Value.isActive)
                {
                    var queueItems = _emailService.GetQueueItemsForTemplate(template.Value.name);
                    foreach (var queueItem in queueItems)
                    { 
                        var previousEmails = _contactHistoryService.GetAllForPolicy(queueItem.policyNo);
                        var emailLookup = previousEmails.ToLookup(x => x.contactReference);

                        bool skip = (queueItem.name == DIRECT_POST_WELCOME && emailLookup.Contains(DIRECT_POST_WELCOME)) || emailLookup.Contains(queueItem.name);

                        if (skip)
                            _emailService.DeleteQueueItem(queueItem);
                        else
                        {

                            var policy = _policyService.GetPolicyByPolicyNo(queueItem.policyNo);
                            var status = SendGridService.Send(queueItem.email, $"{policy.firstName} {policy.lastName}", queueItem.policyNo,
                                queueItem.name);

                            if (status == HttpStatusCode.Accepted)
                            {
                                _contactHistoryService.Insert(new ContactHistoryModel()
                                {
                                    contactType = "email",
                                    description = $"{queueItem.name} email sent to {queueItem.email} and was {status}",
                                    contactReference = queueItem.name,
                                    policyId = queueItem.policyId,
                                    policyNo = queueItem.policyNo,
                                    quoteId = queueItem.quoteId,
                                    quoteNumber = queueItem.quoteNumber,
                                    email = queueItem.email
                                });

                                _emailService.DeleteQueueItem(queueItem);
                            }
                            else
                                _logger.Error(
                                    $"Error sending email {queueItem.name} for policy {queueItem.policyNo} to {queueItem.email} ending in status {status}");

                        }
                    }
                }
            }

            return Task.CompletedTask;
        }
        catch (JobExecutionException e)
        {
            _logger.Error($"Error sending emails {e.StackTrace}");
            return Task.CompletedTask;
        }
        catch (Exception e)
        {
            _logger.Error($"Error sending emails {e.StackTrace}");
            return Task.CompletedTask;
        }

        return Task.CompletedTask;
    }
}

标签: quartz.netquartzquartz.net-3.0

解决方案


推荐阅读