Quartz.net服务,Scheduler已断开连接或在服务器上不存在

时间:2013-09-24 13:46:35

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

我正在使用Quartz.net 2.2作为服务安装。使用AdoJobStore将作业存储在ms sql express中。这些工作是从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 type)+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 context,HttpApplication app)+9189101   System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext,HttpContext context,MethodInfo [] handlers)+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 context)+9104200   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context)+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);
}

2 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:0)

我的设置与您大致相同:

  • 服务: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();