Quartz Scheduler 未在远程服务器上更新

Quartz Scheduler not updating on remote server

我创建了一个 MVC 应用程序,我在其中实现了 Quartz 调度程序以在早上的特定时间提取汇率。它适用于 Dev,但是当我上传到远程服务器时它不起作用。

问题出在远程服务器上,Quartz Scheduler 根本没有触发,因此无法检索汇率。

是否需要将某些内容复制到远程服务器 有没有我需要设置的设置。

我就是这样实现汇率拉动的。

public class JobScheduler
{
    public static async Task Start()
    {
        ISchedulerFactory factory = new StdSchedulerFactory();
        IScheduler scheduler = await factory.GetScheduler();

        IJobDetail job = JobBuilder.Create<HelloJob>()
            .WithIdentity("name", "group")
            .UsingJobData("Name", "Bob")
            .Build();

        ITrigger trigger = TriggerBuilder.Create()
            .WithDailyTimeIntervalSchedule
            (s => 
            s.WithIntervalInHours(24)
            .OnEveryDay()
            .StartingDailyAt(TimeOfDay.HourAndMinuteOfDay(14,08))
            )
            .Build();
        await scheduler.ScheduleJob(job, trigger);
        await scheduler.Start();
        //Thread.Sleep(TimeSpan.FromMinutes(10));
        //await scheduler.Shutdown();
    }
}


public class HelloJob : IJob
{
    public async Task Execute(IJobExecutionContext context)
    {
        DateTime now = DateTime.Now;
        var rate = GetRate();

        if (rate != 0)
        {
            System.Diagnostics.Debug.WriteLine($"Exchange Rate: {rate}");

            using (var connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Default"].ConnectionString))
            {
                if (connection.State == System.Data.ConnectionState.Closed)
                    await connection.OpenAsync();
                var cmd = new SqlCommand($"SELECT Value FROM AppConfigurations WHERE Name = '{AppConfigarationItems.FallBackExchangeRate}'", connection);

                object value = cmd.ExecuteScalar();

                if (value == null)
                {
                    var sql = $@"INSERT INTO AppConfigurations (Name,Value,DoubleValue,LastUpdateDate)
                             VALUES ('{AppConfigarationItems.FallBackExchangeRate}','{rate.ToString().Replace(',', '.')}',{rate.ToString().Replace(',', '.')},'{now}')";
                    cmd = new SqlCommand(sql, connection);

                    int result = cmd.ExecuteNonQuery();
                }
                else
                {
                    var sql = $@"UPDATE AppConfigurations 
                             SET Value = '{rate.ToString().Replace(',', '.')}',
                             DoubleValue = {rate.ToString().Replace(',', '.')},
                             LastUpdateDate = '{now}'
                             WHERE Name = '{AppConfigarationItems.FallBackExchangeRate}'";
                    cmd = new SqlCommand(sql, connection);

                    int result = cmd.ExecuteNonQuery();


                }
            }
        }
    }




    protected override void Application_Start(object sender, EventArgs e)
    {
        System.Globalization.CultureInfo.DefaultThreadCurrentCulture = new System.Globalization.CultureInfo("en-ZA");
        AbpBootstrapper.IocManager.IocContainer.AddFacility<LoggingFacility>(f => f.UseLog4Net().WithConfig("log4net.config"));
        base.Application_Start(sender, e);
        JobScheduler.Start().Wait();
    }

它可能与 IIS 及其处理应用程序池回收的方式有关,也可能无关

这在过去对我有用。

  1. 转到 IIS 管理器 -> 应用程序池 -> 创建一个新池,任意命名

  2. Select 调度程序池 -> 高级设置

  3. 在常规部分,在启动模式下,Select AlwaysRunning 或 true(取决于 IIS 版本)

  4. 在Process Model Section->Idle Timeout(minutes)设置为0(意思是:No Idel timeout)

  5. 在Recycling部分->Regular time Interval设置为0(意思是:不回收)

  6. 将您的 Quartz 站点部署到该应用程序池中。

  7. 向 "wake your app up" 池发送一个请求,它将 运行 直到你停止它。

您还可以在托管服务器上安装一些工具,例如 Keep Alive server for IIS 6.0 and 7.5 它会在应用程序池回收后使应用程序保持活动状态,并且无需更改或设置太多配置。