How can I "discard" new task for being queue if a command is already processing?


I’ve Hangfire setup on a Windows Service, which I start basically with _server = new BackgroundJobServer();

I’ve somethings like 30 commands configured, each with different Command/Parameters (which is a basic setup I believe).

Each task must be continuously executed every 1 Minute. So I’ve setup columns Cron and Frequency respectively as */1 * * * * and Every 1 minutes.

The problem is this: if I queue the 30 commands, and some of them takes more than 1 minute (i.e. 10 minutes due to heavy process to be executed), it continuously queue every task (also the ones which is already processing), resulting in a blocking/infinitely queue for the task which can’t de-queue in 1 minute.

How can I resolve it avoid the re-queue of already processing task?


No ones can help me on this basic request?

I add some additional info (since can’t edit the main question):

Example of method (i.e. Command) I have:

public void CMS1Integration(string systemCode)
public void CMS2Integration(string systemCode)
public void CMS3Integration(string systemCode)

This way, method CMS1Integration can run in parallel, but a single one for each systemCode I pass. So CMS1Integration("cms1Name1") + CMS1Integration("cms1Name2") can run in parallel, but not CMS1Integration("cms1Name1") + CMS1Integration("cms1Name1") (because it have the same systemCode).

Note: they are queued as recurring-jobs:

RecurringJob.AddOrUpdate(hangFireCmd.Name, GetAction(hangFireCmd), hangFireCmd.Cron, TimeZoneInfo.Local);

Looking in the Set table, I find than this list (as example):

Id	Key	Score	Value	ExpireAt
24279	recurring-jobs	1717657740	cms1Name1	NULL
24280	recurring-jobs	1717657740	cms1Name2	NULL
24281	recurring-jobs	1717657740	cms1Name3	NULL
24282	recurring-jobs	1717657740	cms2Name1	NULL
24283	recurring-jobs	1717657740	cms2Name2	NULL
24284	recurring-jobs	1717711800	cms3Name1	NULL
24285	recurring-jobs	1717657740	cms3Name2	NULL
24286	recurring-jobs	1717657740	cms3Name3	NULL
24287	recurring-jobs	1717657740	cms3Name4	NULL

Please, can you help me?

1 Like

No support here for this kind of stuff?