在hangfire中如何使一些方法依赖于运行之前的另一种方法?

How to make some methods depends on another method before run in hangfire?

我有这个 api 端点方法,它使用 Hangfire。如何确保 PreIngestion()IngestA()IngestB() 可以执行之前先完成?

[HttpGet]
[Route("IngestFiles")]
public IActionResult IngestFiles(string cronExpression = "0")
{
     RecurringJob.AddOrUpdate<IIngestService>(x => x.PreIngestion(), cronExpression, TimeZoneInfo.Local);

     RecurringJob.AddOrUpdate<IIngestService>(x => x.IngestA(), cronExpression, TimeZoneInfo.Local);
     RecurringJob.AddOrUpdate<IIngestService>(x => x.IngestB(), cronExpression, TimeZoneInfo.Local);

     return Ok();
}

我可以使用 ContinueJobWith 方法来完成,但我需要安排它。

由于 QueueAttribute 不适合重复性工作, 你可以创建一个辅助方法来像 Anton 所说的那样将它们排队。

[HttpGet]
[Route("IngestFiles")]
public IActionResult IngestFiles(string cronExpression = "0")
{
     RecurringJob.AddOrUpdate<IIngestService>(x => IngestHelper.Ingest(x), cronExpression, TimeZoneInfo.Local);

     return Ok();
}

RecurringJobHelper.cs

public static class RecurringJobHelper
{
    public static void Ingest(IIngestService ingestService)
    {
        ingestService.PreIngestion();
        ingestService.IngestA();
        ingestService.IngestB();
    }
}