Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to clean up the completed job regularly #38

Open
davidchencloudexceed opened this issue May 24, 2021 · 4 comments
Open

How to clean up the completed job regularly #38

davidchencloudexceed opened this issue May 24, 2021 · 4 comments

Comments

@davidchencloudexceed
Copy link

davidchencloudexceed commented May 24, 2021

Hello,
I have a problem regarding cleanning up the completed job. I tried to use the attribute to define the expiration/life time.

public class HangfireJobRentionAttribute : JobFilterAttribute, IApplyStateFilter
 {
     public void OnStateApplied(ApplyStateContext context, IWriteOnlyTransaction transaction)
     {
         context.JobExpirationTimeout = TimeSpan.FromMinutes(1);
     }

     public void OnStateUnapplied(ApplyStateContext context, IWriteOnlyTransaction transaction)
     {
         context.JobExpirationTimeout = TimeSpan.FromMinutes(2);
     }
 }

After apply the attribute, I do see the hangfire pick it up in my dashboard. It said that it should be auto delted 28 min ago.
Capture

However, I don't see the reduction of the memory footprint of my hangfire application. It keeps going up.

Does MemoryStorage has some build in clean up mechanism like SQL?

https://discuss.hangfire.io/t/does-hangfire-clear-down-old-job-data/2294/2

public SqlServerStorageOptions()
{
    TransactionIsolationLevel = null;
    QueuePollInterval = TimeSpan.FromSeconds(15);
    SlidingInvisibilityTimeout = null;
#pragma warning disable 618
    InvisibilityTimeout = TimeSpan.FromMinutes(30);
#pragma warning restore 618
    JobExpirationCheckInterval = TimeSpan.FromMinutes(30);
    CountersAggregateInterval = TimeSpan.FromMinutes(5);
    PrepareSchemaIfNecessary = true;
    DashboardJobListLimit = 10000;
    _schemaName = Constants.DefaultSchema;
    TransactionTimeout = TimeSpan.FromMinutes(1);
}
@perrich
Copy link
Owner

perrich commented May 24, 2021

Hi,

The HangfireJobRentionAttribute is not used.
The ExpirationManager uses the ExpireAt (IExpirable interface) property of the job.

@davidchencloudexceed
Copy link
Author

thank you @perrich. How to set the job's ExpireAt property? I try to set the jobexpireationtimeout at the globalconfiguraiton. (I have to download the src code of hangfire and change the source to remove the 1 hour limit)
However, I don't see InMemory storage will honor the change as my memory consumption same as before.

Hangfire.GlobalConfiguration.Configuration
                .SetDataCompatibilityLevel(CompatibilityLevel.Version_170)
                .UseSimpleAssemblyNameTypeSerializer()
                .UseRecommendedSerializerSettings()
                .UseMemoryStorage(new MemoryStorageOptions
                {
                     JobExpirationCheckInterval = TimeSpan.FromMinutes(1)
                })
                .**WithJobExpirationTimeout(TimeSpan.FromMinutes(1))**
                .UseAutofacActivator(container);

@davidchencloudexceed
Copy link
Author

find out why. InMemory did honor the setting. It is the one by one for loop detele slow the clean up.

@perrich
Copy link
Owner

perrich commented May 24, 2021

The loop is not done one by one but by 1000 (of one of the managed type).

@perrich perrich added bug and removed bug labels May 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants