请帮忙。如何在BackgroundJob的派生类中获取当前作业ID?在构造函数或Execute方法中。无论如何。
Update1我以另一种方式添加后台作业。在Aspnetboilerplate文档中建议的方法。像这样:
await _backgroundJobManager.EnqueueAsync<ImportContactListJob, ImportContactListJobArgs>(
new ImportContactListJobArgs(){someargs});
Then my method stars from overriding method execute in BackgroundJob inheritance class.
public override void Execute(ImportContactListJobArgs args)
{
//job here
}
我无法在EnqueueAsync中传递null值,因为没有重载方法。
这没有内置的方法。
但你可以使用ABP的Hangfire Integration并做this:
为了实现您的目标,只需将
PerformContext
添加到您的工作方法:public void SendEmail(string name, PerformContext context) { string jobId = context.BackgroundJob.Id; }
在排队工作时通过
null
:BackgroundJob.Enqueue(() => SendEmail(name, null));
在实际执行作业时,它将被正确的上下文替换。
我无法在EnqueueAsync中传递null值,因为没有重载方法。
把PerformContext
放在ImportContactListJob
的构造函数中。