英文:
Hangfire Service Not Running
问题
我正在尝试在我的ASP.Net Core 7 Web API项目中使用Hangfire进行后台作业。当我启动应用程序并查看控制台日志时,显示如下内容:
看起来Hangfire已经启动,但我的应用程序从未发送它应该发送的电子邮件。
我如下调用服务:
BackgroundJob.Enqueue(() => SendEmailConfirmationToken(sentToken, newUser));
当我检查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
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(() => SendEmailConfirmationToken(sentToken, newUser));
And when I check the Hangfire dashboard I see the job enqueued but never executed
These are the packages and the versions of Hangfire that I have in my application
<PackageReference Include="Hangfire.AspNetCore" Version="1.8.3" />
<PackageReference Include="Hangfire.Core" Version="1.8.3" />
<PackageReference Include="Hangfire.PostgreSql" Version="1.19.12" />
But when I do this,
Task.Run(async () => 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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论