[英]Recurring job in hangfire is not fired
无论我使用什么Schedule,都不会触发我在Hangfire中进行的定期工作。我尝试使用BackgroundJob
只是为了确保某些东西可以正常工作。 我还检查了数据库,并使用计划的作业正确填充了“哈希”表。
这是我正在使用的代码:
try
{
using(var server = new BackgroundJobServer(serverOptions,storage))
{
Log("Hangfire server started");
RecurringJob.AddOrUpdate("Mail", () =>
_notificationHelper.SendEmail(result)
, Cron.MinuteInterval(1), TimeZoneInfo.Local
);
//BackgroundJob.Enqueue(() => _notificationHelper.SendEmail(result));
}
}
那我在做什么错呢?
如果您查看Hangfire仪表板,它将告诉您正在运行多少BackgroundJobServer。 如果运行的BackgroundJobServers数量为零,则Hangfire将不执行任何操作,直到启动一个。
由于您使用的是BackgroundJobServer
在using
,创建循环作业后,它被设置。 触发重复作业或不创建作业时, BackgroundJobServer
必须处于活动状态。 您可以在程序开始时启动BackgroundJobServer
,并在关闭程序时将其处置。 或者,您可以在单独的Windows服务应用程序中运行BackgroundJobServer
,以便在计算机打开时始终在后台运行。
要了解有关设置后台服务器的更多信息,请参见: http : //docs.hangfire.io/en/latest/background-processing/
当您的应用程序启动时,hangfire会自动创建一个服务器,该服务器就是您的计算机IIS,其他从using块中删除hangfire statrup代码的事物,以及下面的IIS Server级别的一些配置,您必须在任何位置实现使用Hangfire。
我也遇到过同样的问题,在google中搜索了同样的问题后,我从下面的链接中获得了解决方案,其中提到了一些配置部分,这对于持续运行您的工作非常重要。
http://docs.hangfire.io/en/latest/deployment-to-production/making-aspnet-app-always-running.html
-----以下是您必须在全局applicationHost.config文件(%WINDIR%\\ System32 \\ inetsrv \\ config \\ applicationHost.config)中进行的配置。
<applicationPools>
<add name="MyAppWorkerProcess" managedRuntimeVersion="v4.0" startMode="AlwaysRunning" />
</applicationPools>
<!-- ... -->
<sites>
<site name="MySite" id="1">
<application path="/" serviceAutoStartEnabled="true"
serviceAutoStartProvider="ApplicationPreload" />
</site>
</sites>
<!-- Just AFTER closing the `sites` element AND AFTER `webLimits` tag -->
<serviceAutoStartProviders>
<add name="ApplicationPreload" type="WebApplication1.ApplicationPreload, WebApplication1" />
</serviceAutoStartProviders>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.