Hangfire 服务未运行

huangapple go评论67阅读模式
英文:

Hangfire Service Not Running

问题

我正在尝试在我的ASP.Net Core 7 Web API项目中使用Hangfire进行后台作业。当我启动应用程序并查看控制台日志时,显示如下内容:

Hangfire 服务未运行

看起来Hangfire已经启动,但我的应用程序从未发送它应该发送的电子邮件。

我如下调用服务:

BackgroundJob.Enqueue(() => SendEmailConfirmationToken(sentToken, newUser));

当我检查Hangfire仪表板时,我看到作业已经排队,但从未执行:

Hangfire 服务未运行

这些是我应用程序中的Hangfire包和版本:

<PackageReference Include="Hangfire.AspNetCore" Version="1.8.3" />
<PackageReference Include="Hangfire.Core" Version="1.8.3" />
<PackageReference Include="Hangfire.PostgreSql" Version="1.19.12" />

但当我这样做时:

Task.Run(async () => SendEmailConfirmationToken(sentToken, newUser));

邮件就会被发送。

所以,我知道问题不是来自SendEmailConfirmationToken() 方法;

请问我应该如何解决这个问题?

英文:

I am trying to use Hangfire for background job in my ASP.Net Core 7 Web API project.
When I start the application and look at the console logs, it shows the following

Hangfire 服务未运行

which appears that the hangfire starts but my application never sends the email it is meant to send.

I call the service as follows:

BackgroundJob.Enqueue(() =&gt; SendEmailConfirmationToken(sentToken, newUser));

And when I check the Hangfire dashboard I see the job enqueued but never executed

Hangfire 服务未运行

These are the packages and the versions of Hangfire that I have in my application

 &lt;PackageReference Include=&quot;Hangfire.AspNetCore&quot; Version=&quot;1.8.3&quot; /&gt;
&lt;PackageReference Include=&quot;Hangfire.Core&quot; Version=&quot;1.8.3&quot; /&gt;
&lt;PackageReference Include=&quot;Hangfire.PostgreSql&quot; Version=&quot;1.19.12&quot; /&gt;

But when I do this,

Task.Run(async () =&gt; SendEmailConfirmationToken(sentToken, newUser));

The email get's sent.

So, I know the problem is not from the SendEmailConfirmationToken() method;

How can I get this resolved please?

答案1

得分: 0

抱歉,我刚刚发现在将Hangfire服务添加到我的应用程序时,我在program.cs文件中遗漏了以下行:

builder.Services.AddHangfireServer();

这就是问题所在。
我已经添加了它,现在Hangfire正如预期地工作。感谢您的帮助。

英文:

Sorry, I just discovered that I omitted the following line in the program.cs file while adding the hangfire service to my application

builder.Services.AddHangfireServer();

That was the issue.
I have added it and Hangfire is working as expected now. Thank you for your efforts to help

huangapple
  • 本文由 发表于 2023年6月29日 01:49:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/76575607.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定