Text/name for background jobs?


#1

Hi,

I’m wondering if it’s possible to set a name/text on a background job? Having 1000+ successful SendOrder() is nice but isn’t very useful when suddenly you have 2 SendOrder() that has failed.

I would like to have a string like “Send order #1202 to warehouse” for the background job instead of the actual method name. That way it would be a lot easier to check what went wrong.

Sincerely

David Sinclair


#2

Succeeded jobs and failed jobs are already being shown on different pages. In your case, the failed jobs page will contain only two failed jobs, so you can easily debug them. Can you show the screenshot of a dashboard page that makes you unhappy?


#3

Yes I’m fully aware of that. It’s just that it’s missing context and information that is relevant. I would like to have the possibility to set a text like this:

BackgroundJob.Enqueue(() => OrderService.CopyOrderToLevel4(orderId), string.Format(“Send order #{0} to warehouse”, orderId));

So I would have this instead -> http://i.imgur.com/fOVxOpO.jpg

That information should replace the method called. If I want more information about the job I should be able to dig into it and see the method being called and stacktrace etc, having a context when debugging is very useful.


#4

I told you about page separation only because I can’t understand the following sentence:

Having 1000+ successful SendOrder() is nice but isn’t very useful when suddenly you have 2 SendOrder() that has failed.

Nevertheless I agree that textual method representation makes debugging simpler. Display name relates exactly to the calling method, so this feature can be implemented with DisplayNameAttribute:

[DisplayName("Send order #{0} to warehouse")]
public void CopyOrderToLevel4(int orderId)
{
    // Processing
}

Positional display name arguments can be substituted from method arguments. Job creation code remains simple:

BackgroundJob.Enqueue<IOrderService>(x => x.SendOrderToLevel4(orderId));

What do you think?


#5

Sure it sounds like a way to handle it. But how do I pass the parameter to the attribute?


#6

Positional argument values will be substituted automatically with the background method call argument values:

String.Format(attribute.DisplayName, job.Arguments);

#7

Awesome, that solves my problem perfectly.


Customize Dashboard (Succeeded & Failed List)
#8

Added work item – https://github.com/odinserj/HangFire/issues/144.


closed #9