Passing JobId to job


#1

I was using 1.4.6. I’m upgrading to 1.5.2.

I want to pass the JobId to each job and include the JobId in each log my jobs generate. Each of my job methods has a string parameter to hold the JobId. So each method called by Hangfire might look like this:

public void ProcessReminder(string jobId, int actionId)

I was using an IServerFilter and overriding OnPerforming to pass the JobId to my job like this:

filterContext.Job.Arguments[0] = filterContext.JobId;

With the changes between 1.4.6 and 1.5.2, Job.Arguments is deprecated. I’m supposed to use
filterContext.BackgroundJob.Job.Args instead. But Args is a read-only collection, so I can’t assign the JobId to Args[0].

Is there a better way of passing JobId to a job? If not and you’re not planning to add one, does Args have to be a read-only type?


#2

Is there any development in this topic? I’d like to pass a custom id to the background job. Something like this: “BackgroundJob.Schedule(jobId, action, delay);” Is there a way to do it?
Thanks.