We left Russia. We are against aggression and war with Ukraine. It is a tragedy for our nations, it is a nightmare

Successful Backups are not removed when using custom Expire Attribute

Hello,

We have quite a few recurring background jobs running on our server and the succeeded logs can grow quite large so I have a custom attribute which allows you to set the expiration time for a recurring backup job.

public class ExpirationTimeAttribute : JobFilterAttribute, IApplyStateFilter
{
    public ExpirationTimeAttribute(int minutes)
    {
        Minutes = minutes;
    }

    public int Minutes { get; }

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

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

This, at least appears to work fine, when a Job is executed, i can see a message similar to the following

The job is finished. It will be removed automatically in 4 minutes.

Which is correct for when the Job finished and the time i have set in the Attribute. This issue is that when the 4 minutes has passed, it doesn’t get cleared out of the Succeeded logs and i start to see messages like this

The job is finished. It will be removed automatically 23 minutes ago.

And then it doesn’t actually get removed until at least an hour later. The attribute is actually set to 15 minutes. Is there a minimum clean up interval ? If so, is there anyway i can configure this? Thanks

By default, expired entries are removed every hour. You can change this by using the SqlServerOptions.JobExpirationCheckInterval property.