请帮忙。如何在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中传递空值,因为没有重载方法。
答案 0 :(得分:0)
没有内置的方法可以做到这一点。
但您可以使用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
的构造函数中。