Hangfire.MySqlStorage
Hangfire.MySqlStorage copied to clipboard
Invisibility Timeout Obsolete, but long running jobs need it
I see that the invisibility timeout property is obsolete. My infrastructure has two EC2 instances to serve up our project. Each of these instances has their own hangfire server pointing to the central hangfire mysql database. If the job runs over 30 minutes, the other instance keying of FetchedAt will see it needs to re-fetch the job and spin up the process again.
It seems to me the code is still relying on setting the FetchedAt with this invisibility timeout. What is new approach then for long running jobs and how would one prevent multiple jobs from queueing up w/ out using the timeout property?
I am facing the same issue...
I have a long running jobs that more than 1 hours or more,but it will be auto invoked by different workers ecah 30 minutes.I tried using cancellation tokens in my jobs,but it seems no work.
public static void MaintainRecordData(IJobCancellationToken cancellationToken)
{
string id = Guid.NewGuid().ToString();
try
{
if (isRuning) return;
try
{
isRuning = true;
//通知hangfire程序,即将执行一个长时间作业任务
cancellationToken.ThrowIfCancellationRequested();
DateTime sTime, eTime;
sTime = DateTime.Now;
TaskLog.WriteHangFireLog("标识id:" + id + ",开始执行 HangFire.Task.MaintainDataTask.MaintainRecordData()方法", "当前时间:" + sTime.ToString("yyyy-MM-dd HH:mm:ss"));
RecordClass.MaintainRecordData();
eTime = DateTime.Now;
TimeSpan ts = eTime - sTime;
TaskLog.WriteHangFireLog("标识id:" + id + ",HangFire.Task.MaintainDataTask.MaintainRecordData()方法执行完毕", "当前时间:" + eTime.ToString("yyyy-MM-dd HH:mm:ss") + ",总耗时:" + ts.Minutes + "分钟" + ts.TotalSeconds);
}
finally
{
isRuning = false;
}
}
catch (Exception ex)
{
BM.Core.Log.Log4NetHelper.Error("HangFire系统调用MaintainDataTask.MaintainRecordData方法时异常,标识id" + id, ex);
}
}
MYSQL version 5.7.15 HangFire version 1.6.12 Hangfire.MySqlStorage version 1.0.3
Thanks for your time.
@superqbb I did end up just using the invisibility timeout property. It works to extend the timeout but I'm still curious since it is marked as obsolete and it seems as though this is the only way to stop another worker from picking up the job.
new MySqlStorage(mySqlConnectionString, new MySqlStorageOptions
{
InvisibilityTimeout = TimeSpan.FromHours(2)
}
I have tried to set up InvisibilityTimeout but it was no work.
@superqbb I have the same problem. Have you solved it?
Any informations on this issue ? Same problem for me
Any Update on this?? How did u guys fix it?
Same problem here ! It's very anoying...
Same problem here ! Any Update on this?? How did u guys fix it?
Is there a workaround? I have jobs that takes more than 3 days.
@LucasFarley : I finally use the deprecated but still useful InvisibilityTimeout.
InvisibilityTimeout这个参数设置多少合适呢?