imranmomin / Hangfire.AzureCosmosDb

Azure Cosmos DB storage provider for Hangfire
https://www.hangfire.io/
MIT License
17 stars 16 forks source link

CreateExpiredJob expireIn always is set as 30 days #15

Closed robertgm closed 3 years ago

robertgm commented 3 years ago

In CosmosDbConnection we have method to create expire job. Last parameter is expireIn. This parameter is always set as 30 days. There is no way to set custom value, for example 1 day or 7 days:

public override string CreateExpiredJob(Common.Job job, IDictionary<string, string> parameters, DateTime createdAt, TimeSpan expireIn)
        {
bzumhagen commented 3 years ago

Would also like a fix for this.

imranmomin commented 3 years ago

@bzumhagen - this method is an override of JobStorageConnection

https://www.github.com/imranmomin/Hangfire.AzureCosmosDb/tree/develop/src%2FCosmosDbConnection.cs

You will need to check how Hangfire itself pass this value.

Or it could be configuration you need to set while setting up the server

bzumhagen commented 3 years ago

When the background job is enqueued, it is given the 30 day expiration. When the job state is changed, it's supposed to get the configured expiration time.

There is a bug in the cosmos stored procedure to update the jobs, which I have an open PR for here:

https://github.com/imranmomin/Hangfire.AzureCosmosDb/pull/23

You can edit the stored procedure through the Cosmos UI as a temporary fix.

imranmomin commented 3 years ago

Closing this issue as the pull-request was accepted

bzumhagen commented 3 years ago

@imranmomin when do you think you'll release?

imranmomin commented 3 years ago

@bzumhagen - I released a test package. Can you confirm if it works fine. So I can later merge to master and do a final release

https://www.nuget.org/packages/Hangfire.AzureCosmosDB/1.3.0-develop

dotnet add package Hangfire.AzureCosmosDB --version 1.3.0-develop

bzumhagen commented 3 years ago

@imranmomin I can confirm that the storedProcedure fix works fine.

However the iStorageConnection.GetJobData still throws when the job is missing. This seems to be because of the way you handle the task, the resulting exception is wrapped in a System.AggregateException instead of just being a Microsoft.Azure.Cosmos.CosmosException.

See https://docs.microsoft.com/en-us/dotnet/standard/parallel-programming/exception-handling-task-parallel-library

 System.AggregateException: One or more errors occurred. (Response status code does not indicate success: NotFound (404); Substatus: 0; ActivityId: b3e897eb-aa5c-4205-af41-0b2999d53605; Reason: (
Errors : [
  "Resource Not Found. Learn more: https://aka.ms/cosmosdb-tsg-not-found"
]
);)
 ---> Microsoft.Azure.Cosmos.CosmosException : Response status code does not indicate success: NotFound (404); Substatus: 0; ActivityId: b3e897eb-aa5c-4205-af41-0b2999d53605; Reason: (
Errors : [
  "Resource Not Found. Learn more: https://aka.ms/cosmosdb-tsg-not-found"
]