Reputation: 123
I have a web application which has Page1.aspx that does task1 and then enqueue task2 to scheduler in fireAndforget manner.
I am using Hangfire and everything is installed and worked correctly but only once when doLongJob()
had no parameters (while testing). Then I added a parameter (and I will be adding more).
After that I am facing these errors
Page1.aspx.cs
string strMsgID = //task1 returns a value;
BackgroundJob.Enqueue(() => doLongJob(strMsgID));
public void doLongJob(string strMsgID)
{
int status = //task2(strMsgID);
while( status == 2)
{
Thread.Sleep(10000);
status = //task2(strMsgID);
}
}
}
Startup.cs
using Hangfire;
using Microsoft.Owin;
using Owin;
[assembly: OwinStartup(typeof(erp.Startup))]
namespace erp
{
public class Startup
{
public void Configuration(IAppBuilder app)
{
app.UseHangfireDashboard();
app.UseHangfireServer();
}
}
}
Global.asax.cs
protected void Application_Start(object sender, EventArgs e)
{
GlobalConfiguration.Configuration.UseStorage(new MySqlStorage("hangfire"));
}
Upvotes: 3
Views: 4944
Reputation: 29
I had the same issue, in my case I changed the code few weeks ago where I introduced new parameter and did a new deployment to kubenetes and I forgot to delete the old deployment so when some of the request was going to the old pod I was getting this error but after few retries in Hangfier it was successful.
I deleted the old kubernetes deployment and it worked for me.
PS: Both new and old deployment were pointing to the same hangfire queue.
Upvotes: 1
Reputation: 7329
Did you double-check the date on the failed job?
I had a similar issue - turned out I was just looking at the same failed job from before. Because it was the most recent failed job, I didn't think to check if it was older than it looked.
Upvotes: 0
Reputation: 2652
I had a similar issue and it turned out to be from the storage connection.
In your code, I think you are passing a string "hangfire"
while you should pass the connection string
GlobalConfiguration.Configuration.UseStorage(new MySqlStorage(connectionString));
You could find more options for MySQL configuration with hangfire here
Upvotes: 0