Hangfire is stuck processing


#1

I’m having hard times with Hangfire. The code pieces below worked perfectly until now. We decided to extend a program that uses the code pieces below. So we exactly copied everything from the old program to new one and just changed the content of the background method. We already have Hangfire set up on our live site and it’s working perfectly. However, when we deployed the new program it got stuck processing only for the new program. Other programs using Hangfire are working fine.

All the records are inserted to database. Everything seems fine but it just gets stuck processing. I was able to debug the new program locally before I deploy, it was hitting the breakpoint at the first line of the background method. After I deployed it stopped hitting the breakpoint locally but when I check the dashboard it says processing. I tried to run the program locally both on the live server and local server but I was never able to hit the breakpoint. But when I tried that again after some time I was able to hit the breakpoint, so I thought issue may be solve. I deployed the new program and I got the same errors again.

We have multiple Hangfire servers. One is the actual live web site and the other ones are local servers which are used for development purposes. One time I got an exception like this:

System.InvalidOperationException: The type ControllerName does not contain a method with signature Method(...) at HangFire.Storage.InvocationData.Deserialize()

So I thought maybe our live server doesn’t see the new method signature but everything was deployed as usual. I can’t really think of any other solution now.

When I set breakpoints to my HangfireAction methods it’s hitting the breakpoints until OnPerforming. Then I continue and it gets stuck.

Here is how I call my method

var jobId = BackgroundJob.Enqueue( 
                () => Method(number1, number2, number3, userName, customer, p1, p2, code, shipping, JobCancellationToken.Null)
            );

Method:

[AutomaticRetry(Attempts = 0, OnAttemptsExceeded = AttemptsExceededAction.Delete)]
[HangfireAction]
[DisableConcurrentExecution(timeoutInSeconds: 60 * 60)]
public void Method(String number1, String number2, String number3, String userName, String customer, String p1, String p2, String code, string shipping, IJobCancellationToken cancellationToken)

Here is my HangfireAction class:

public class HangfireActionAttribute : JobFilterAttribute,
IClientFilter, IServerFilter, IElectStateFilter, IApplyStateFilter
{
    public void OnCreating(CreatingContext context)
    {
    }
    public void OnCreated(CreatedContext context)
    {
    }
    public void OnPerforming(PerformingContext context)
    {
    }
    public void OnPerformed(PerformedContext context)
    {
        //Do Stuff
    }
    public void OnStateElection(ElectStateContext context)
    {
        //Do Stuff
    }
    public void OnStateApplied(ApplyStateContext context, IWriteOnlyTransaction transaction)
    {
    }
    public void OnStateUnapplied(ApplyStateContext context, IWriteOnlyTransaction transaction)
    {
    }
}

#2

If you register a custom IJobFilterProvider, you must include the GlobalFilters.Filters in the result of the GetFilters method. For example:

public virtual IEnumerable GetFilters(Job job)
{
var result = GlobalJobFilters.Filters.AsEnumerable()
.Concat(new JobFilter[] {
new JobFilter(new QueueAttribute(GetQueueName(job)), JobFilterScope.Method, null)
});
return result;
}