How to attach "meta-data" to jobs? Is it possible?

Tags: #<Tag:0x00007fb5026e2f08> #<Tag:0x00007fb5026e2e18>

I am looking to implement Hangfire within an Asp.Net Core application.

However, I’m struggling to understand how best to prevent the user from creating duplicate Hangfire “Fire-and-Forget” jobs.

The Problem

Say the user, via the app, creates a job that does some processing relating to a specific client. The process may take several minutes to complete. I want to be able to prevent the user from creating another job for the same client while there are other jobs for that client still being processed by Hangfire (i.e. there can only be 1 processing job for a specific client at any one time, although several different clients could also each have their own job being processed).

Solution?

I need a way to attach additional meta-data (in this example, the client id) to each job as it is created, which I can then use to interrogate the jobs currently processing in Hangfire to see if any of them relate to the client id in question.

It seems like such a basic feature that would prove so useful for such scenarios, but I’m coming to the conclusion that such a thing isn’t supported, which surprises me.

… Unless you know different. :slight_smile:

Hangfire looks great, and I’m keen to use it, but this might be a show-stopper for me.

Any advice would be greatly received.

Thanks

1 Like