Hangfire 后台作业未触发

问题描述 投票:0回答:1

嗨,我有一个在 HangfireController 中初始化的后台作业,我希望只有在单击按钮后才会触发该作业,该作业不会触发并在我调用的方法中命中我的断点,并且不会出现错误,我的其他经常性工作按其应有的方式工作,我可能会错过一些东西吗?请参阅下面的代码

Hangfire 控制器

public class HangfireController : Controller
{
public HangFireController(my parameters...) // my constructor
{
Int SID = 0;
 RecurringJob.AddOrUpdate("Import Users", () => RunLoadUsers(), "0 0,3,6,9,12,15,18,21 * * *", TimeZoneInfo.Local);

            RecurringJob.AddOrUpdate("Test Example", () => TestData(), "*/15 * * * * *", TimeZoneInfo.Local); //run every 15 sec
            BackgroundJob.Enqueue(()=> RunSaveStatus(SID)); //new job
}  

public void RunSaveStatus(int SID)
{
  //where i placed breakpoint,this point is not reached
  //my logic here
}

}

家庭控制器

{
     //my button calls this method when it is clicked
     [HttpPut("UpdateStatus")]
        public IActionResult UpdateStatus(int key, string values)
        {
            var SID = 10;
             BackgroundJob.Enqueue<HangfireController>(x=>x.RunSaveStatus(SID));
        }
}

StartUp.CS 我在哪里配置hangfire来初始化

   string hangfireConnectionString = Configuration.GetConnectionString("myConnDB");
            services.AddHangfire(configuration =>
            {
                configuration.SetDataCompatibilityLevel(CompatibilityLevel.Version_170)
                .UseSimpleAssemblyNameTypeSerializer()
                .UseRecommendedSerializerSettings()
                
                //.UseBatches()
                //.UsePerformanceCounters()
                .UseSqlServerStorage(hangfireConnectionString, new SqlServerStorageOptions
                {
                    CommandBatchMaxTimeout = TimeSpan.FromMinutes(5),
                    SlidingInvisibilityTimeout = TimeSpan.FromMinutes(5),
                    QueuePollInterval = TimeSpan.Zero,
                    UseRecommendedIsolationLevel = true,
                    UsePageLocksOnDequeue = true,
                    DisableGlobalLocks = true
                });
            });

            services.AddHangfireServer();

NB 两个重复作业工作得很好,只有 Backround.enqueue 作业不会触发。

asp.net-core hangfire ef-core-5.0 hangfire-sql
1个回答
0
投票

可能您有多个 Hangfire 服务器,并且后台作业可以在另一台服务器上处理。打开 Hangfire 仪表板并检查排队作业处理的成功作业。Succeeded job

© www.soinside.com 2019 - 2024. All rights reserved.