marcoCasamento / Hangfire.Redis.StackExchange

HangFire Redis storage based on original (and now unsupported) Hangfire.Redis but using lovely StackExchange.Redis client
Other
448 stars 108 forks source link

Overdue jobs are not completely cleaned up #113

Closed jeremy7710 closed 2 years ago

jeremy7710 commented 2 years ago

At the beginning, I set an expiration time of 30 seconds and everything worked normally.

Once I set the TTL to 0 seconds, some keys that were not deleted began to appear, and I did not find these tasks no matter where they were succeeded or failed. As shown in the figure below, there are about 2,000 keys of this kind. Is there anyone have the same situation? Does it mean that 0 seconds cannot be set at present? Thanks.

My Hangfire.Redis.StackExchange version is 1.7.2. My Hangfire.Core version is 1.7.5.

The code for setting TTL is like below:

    /// <summary>
    /// HangFire.Job有效期限 0 秒
    /// 註: HangFire.Job執行/取消後設定TTL,避免記憶體占用太久)
    /// </summary>
    public class HangFireJobExpireTimeAttr_0S : JobFilterAttribute, IApplyStateFilter
    {
        /// <summary>
        /// Job調用後,該Job物件留存HangFire時間
        /// </summary>
        /// <param name="context"></param>
        /// <param name="transaction"></param>
        public void OnStateApplied(ApplyStateContext context, IWriteOnlyTransaction transaction)
        {
            context.JobExpirationTimeout = TimeSpan.FromSeconds(0);
        }
        /// <summary>
        /// Job取消後,該Job物件留存HangFire時間
        /// </summary>
        /// <param name="context"></param>
        /// <param name="transaction"></param>
        public void OnStateUnapplied(ApplyStateContext context, IWriteOnlyTransaction transaction)
        {
            context.JobExpirationTimeout = TimeSpan.FromSeconds(0);
        }
    }

image

jeremy7710 commented 2 years ago

I change TimeSpan to 1 second, and there is no key with TTL=-1.

TimeSpan.FromSeconds(1);

I think that's it. The expiration time of 1 second is still acceptable to me.