我的应用程序正在使用Hangfire进行后台作业处理。 我创建的后台作业如下:使用ContinueWith时,在Hangfire中排队的子作业有哪些优先级?
var parentJobId = _backgroundJobClient.Enqueue<IMyService>(x => x.ParentMethod(id));
_backgroundJobClient.ContinueWith<IMyService>(parentJobId, x => x.ChildMethod(id));
_backgroundJobClient.Enqueue<IMyService>(x => x.OtherMethod1(id));
_backgroundJobClient.Enqueue<IMyService>(x => x.OtherMethod2(id));
这些方法在服务定义如下:
public interface IMyService
{
[Queue(HangfireQueuePriority.Default)]
void ParentMethod(int id);
[Queue(HangfireQueuePriority.Default)]
void ChildMethod(int id);
[Queue(HangfireQueuePriority.Default)]
void OtherMethod1(int id);
[Queue(HangfireQueuePriority.Critical)]
void OtherMethod2(int id);
}
我想的ChildMethod要尽快父作业运行完毕。 我对ContinueWith的理解是,子作业在父作业之后运行,但在Hangfire文档中未指定子任务将运行的时间。
我的问题是子任务相对于队列中其他任务的“优先级”是什么? 队列中定义的任何任务是否有可能在ParentMethod和ChildMethod之间运行?例如OtherMethod1或OtherMethod2
这很有道理。但是,有一点我不清楚。 在开始处理ParentMethod(在处理ChildMethod之前)之后,将紧急任务(OtherMethod2)添加到队列时会发生什么情况? 首先处理哪个任务:Crital任务(OtherMethod2)或ChildMethod任务? –