Hangfire.MySqlStorage icon indicating copy to clipboard operation
Hangfire.MySqlStorage copied to clipboard

Invisibility Timeout Obsolete, but long running jobs need it

Open erickpearson opened this issue 7 years ago • 11 comments

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?

erickpearson avatar Feb 27 '17 22:02 erickpearson

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. image

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 avatar Apr 05 '17 16:04 superqbb

@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)
                        }

erickpearson avatar Apr 05 '17 16:04 erickpearson

I have tried to set up InvisibilityTimeout but it was no work.

superqbb avatar Apr 07 '17 06:04 superqbb

@superqbb I have the same problem. Have you solved it?

gitkevin1106 avatar Jun 07 '18 03:06 gitkevin1106

Any informations on this issue ? Same problem for me

MeTaLiKiD avatar Nov 16 '18 10:11 MeTaLiKiD

Any Update on this?? How did u guys fix it?

francisfai avatar Feb 26 '19 06:02 francisfai

Same problem here ! It's very anoying...

Safirion avatar Mar 27 '19 10:03 Safirion

Same problem here ! Any Update on this?? How did u guys fix it?

LucasFarley avatar Apr 14 '19 00:04 LucasFarley

Is there a workaround? I have jobs that takes more than 3 days.

LucasFarley avatar Apr 14 '19 01:04 LucasFarley

@LucasFarley : I finally use the deprecated but still useful InvisibilityTimeout.

Safirion avatar Apr 14 '19 09:04 Safirion

InvisibilityTimeout这个参数设置多少合适呢?

lifazheng avatar Aug 12 '19 06:08 lifazheng