我的應用程序正在使用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任務? –