【问题标题】:Quartz.net service, Scheduler has been disconnected or does not exist at serverQuartz.net 服务,Scheduler 已断开连接或在服务器上不存在
【发布时间】:2013-09-24 13:46:34
【问题描述】:

我正在使用作为服务安装的 Quartz.net 2.2。作业存储在 ms sql express 中,使用 AdoJobStore。这些作业是从 asp.net 4 网站管理的。 一切正常,正如预期的那样:服务正在运行,作业已正确存储和触发。 我面临的问题是,每天早上 7 点之后(这是应用程序池回收的时间)并且我访问该站点时,都会出现此错误:

对象“/QuartzScheduler”已断开连接或在服务器上不存在。

[RemotingException: 对象“/QuartzScheduler”已断开连接或在服务器上不存在。] System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) +9443827 System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 类型) +345 Quartz.Simpl.IRemotableQuartzScheduler.get_SchedulerName() +0 Quartz.Impl.RemoteScheduler.b__6(IRemotableQuartzScheduler x) +8 Quartz.Impl.RemoteScheduler.CallInGuard(Func`2 func) +61

[SchedulerException: 与远程调度程序通信时出错。] Quartz.Impl.RemoteScheduler.CallInGuard(Func`2 func) +100 Quartz.Impl.RemoteScheduler.get_SchedulerName() +92 Quartz.Impl.SchedulerRepository.Bind(IScheduler sched) +65 Quartz.Impl.StdSchedulerFactory.Instantiate() +1815 Quartz.Impl.StdSchedulerFactory.GetScheduler() +102 ASP.global_asax.Application_Start(Object sender, EventArgs e) +241

[HttpException (0x80004005): 与远程调度程序通信时出错。] System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext 上下文,HttpApplication 应用程序)+9189101 System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext,HttpContext 上下文,MethodInfo[] 处理程序)+131 System.Web.HttpApplication.InitSpecial(HttpApplicationState 状态,MethodInfo[] 处理程序,IntPtr appContext,HttpContext 上下文)+194 System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +339 System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +253

[HttpException (0x80004005): 与远程调度程序通信时出错。] System.Web.HttpRuntime.FirstRequestInit(HttpContext 上下文) +9104200 System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext 上下文)+97 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +256

在此之后,如果我去服务器,我停止/启动 Quartz.net 服务,那么站点将正确启动。

每次我通过 FTP 上传修改的 web.config 或修改的另一个文件时都会发生同样的事情,这会导致网站重新启动。在这里我得到了同样的错误,我可以绕过停止和重新启动 Quartz.net 服务。

这是网站的 global.asax

public static ISchedulerFactory SchedulerFactory;
public static IScheduler Scheduler;

void Application_Start(object sender, EventArgs e)
{
    NameValueCollection p = new NameValueCollection();
    p["quartz.scheduler.instanceName"] = "MyScheduler";
    p["quartz.scheduler.proxy"] = "true";
    p["quartz.threadPool.threadCount"] = "0";
    p["quartz.scheduler.proxy.address"] = "tcp://localhost:555/QuartzScheduler";

    SchedulerFactory = new StdSchedulerFactory(p);
    Scheduler = SchedulerFactory.GetScheduler(); // <-- The exception seems to occur here

    if (!Scheduler.IsStarted)
        Scheduler.Start();
}

void Application_End(object sender, EventArgs e)
{
    Scheduler.Shutdown(true);
}

【问题讨论】:

    标签: asp.net quartz-scheduler quartz.net


    【解决方案1】:

    由于没有关于此事的答案,我发布了我所做的:
    void Application_End 中删除Scheduler.Shutdown(true); 解决了应用程序回收后出现的问题。
    如果其他人有更好的答案和解释,我会将其标记为答案。

    【讨论】:

    • 我在这里犯了同样的错误
    【解决方案2】:

    我的设置和你差不多:

    • 服务:Quartz 主机
    • MVC 网络应用:Quartz 客户端

    但是,我从来没有遇到过这个错误。以下是我的代码的关键部分,希望对您有所帮助:

    客户端参数

    NameValueCollection properties = new NameValueCollection();
    properties["quartz.scheduler.instanceName"] = config.QuartzInstanceName;
    properties["quartz.scheduler.instanceId"] = "AUTO";
    properties["quartz.scheduler.proxy"] = "true";
    properties["quartz.scheduler.proxy.address"] = "tcp://127.0.0.1:" + config.QuartzPort + "/" + config.QuartzInstanceName;
    

    主机参数

    NameValueCollection properties = new NameValueCollection();
    properties["quartz.scheduler.instanceName"] = config.QuartzInstanceName;
    properties["quartz.scheduler.instanceId"] = "AUTO";
    properties["quartz.scheduler.exporter.type"] = "Quartz.Simpl.RemotingSchedulerExporter, Quartz";
    properties["quartz.scheduler.exporter.port"] = config.QuartzPort;
    properties["quartz.scheduler.exporter.bindName"] = config.QuartzInstanceName;
    properties["quartz.scheduler.exporter.channelType"] = "tcp";
    properties["quartz.scheduler.exporter.channelName"] = "httpQuartz";
    properties["jobStore.type"] = "Quartz.Simpl.RAMJobStore, Quartz";
    

    客户端初始化

    // Note, this runs in an async loop, which keeps on trying to connect until it succeeds
    // This is actually kinda ugly, needs to be refactored, but it works
    
    while (mScheduler == null)
    {
      try
      {
        StdSchedulerFactory schedulerFactory = new StdSchedulerFactory(schedulerFactoryProps);
        mScheduler = schedulerFactory.GetScheduler()
        // Note that I do not use .Start() here
      }
      catch (Exception ex)
      {
      }
    
      if (mScheduler == null)
        Thread.Sleep(SCHEDULER_RETRY_DELAY);
    }
    

    主机初始化

    StdSchedulerFactory schedulerFactory = new StdSchedulerFactory(schedulerFactoryProps);
    mScheduler = schedulerFactory.GetScheduler();
    mScheduler.Start();
    

    【讨论】:

    • 我看到了你的例子,它在某些方面与我的不同。我解决了它删除了 Scheduler.Shutdown(true);我让它运行。我不知道为什么,但是在应用程序回收后解决了这个问题。
    猜你喜欢
    • 2011-09-14
    • 1970-01-01
    • 1970-01-01
    • 2013-05-31
    • 1970-01-01
    • 1970-01-01
    • 2018-10-24
    • 2011-09-24
    • 1970-01-01
    相关资源
    最近更新 更多