Hi I create hangfire jobs and want to give the job a specific name.
In fact I want to add a descriptive name when queueing the job
BackgroundJob.Enqueue(() => HangfireExecuter.ExecuteDevice("JobName’, arg1,arg2,arg3);
How can we do this ?
Now I see in jobshistory Always the same called method
Id Job Total Duration Succeeded
#9 HangfireExecuter.ExecuteDevice 1m 50.414s 18 minutes ago
#8 HangfireExecuter.ExecuteDevice 1m 16.674s 23 minutes ago
#6 HangfireExecuter.ExecuteDevice 30.66s a day ago
#4 HangfireExecuter.ExecuteDevice 2m 48.560s a day ago
#3 HangfireExecuter.ExecuteDevice 3m 46.560s a day ago
#2 HangfireExecuter.ExecuteDeviceWithItsDataControllerFrequency 12.25s a day ago
#1 HangfireExecuter.ExecuteDevice
I actually asked this question as a github issue a while back (https://github.com/HangfireIO/Hangfire/issues/170)
The way that you can do this is that you add a DisplayName attribute to the class that is processing the job and make the description a parameter to the job.
So for example:
public class EmailJobRunner
{
[DisplayName("Email Job - description: {0}")]
public void EmailCustomer(string description, int customerId, string email)
{
}
}
and then execute it:
BackgroundJob.Enqueue<EmailJobRunner>(x => x.Process("Sending email to Joe Bloggs", customerId, emailContents));
Hi,
That’s not a good solution in my case. I have a generic class which can start a lot of different things.
The context is different so I cannot use the display attribute because then I Always have the same description.
fe
public static void ExecuteDevice(int userId, int deviceId, string libPath)
{
…
}
this executes fe thing which do maintenance on a table
or fe imports an excel file
so I need to set the displayattribute in the method
public static void ExecuteDevice(int userId, int deviceId, string libPath)
{
displayName = string.format("JobName : {0}",_service.GetDevice(deviceId).Name);
}
Hi
Is it difficult to implement an additional parameter for adding a jobdecription ?
I think a lot of users will be happy ?
BackgroundJob.Enqueue(() => HangfireExecuter.ExecuteDevice("JobName’, arg1,arg2,arg3);
That person also needs it
As mentioned by @paulduran you can add a description argument to your generic supermethod and generated the friendly description right before scheduling.
[DisplayName("{0}")
void ExecuteDevice(string friendlyDescription, int userId, int deviceId, string libPath)
Hi there, i’ve tried doing this, and adding a BackgroundJob.Enqueue(() => MyMethod(‘test’, a)); But in the Job Description, it still says ‘Could not find target method’.
Does the Dashboard need to A) find the target method with references, in combination with B) adding a DisplayName for this to work?
Thank you.