0

我正在使用作为服务安装的 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 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 state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +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 上下文)+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);
}
4

2 回答 2

2

Since there have been no answers regarding this matter, I'm posting what I did:
Removing Scheduler.Shutdown(true); from void Application_End solves the issue that occured after application recycle.
If someone else has a better answer and explanation I'll mark it as answer.

于 2013-12-11T13:13:22.383 回答
0

我的设置与您大致相同:

  • 服务:石英主机
  • MVC Web 应用程序: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();
于 2013-10-29T16:20:12.777 回答