Skip to content

Commit

Permalink
Fixed MODM-76
Browse files Browse the repository at this point in the history
  • Loading branch information
tmm360 committed May 21, 2021
1 parent bebef3f commit cc73928
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
17 changes: 17 additions & 0 deletions src/MongODM.Hangfire/Extensions/HangfireGlobalConfigExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Etherna.ExecContext.AsyncLocal;
using Etherna.MongODM.HF.Filters;

namespace Hangfire
{
public static class HangfireGlobalConfigExtension
{
#pragma warning disable IDE0060 // Remove unused parameter
public static void UseMongODM(this IGlobalConfiguration config)
#pragma warning restore IDE0060 // Remove unused parameter
{
// Add a default execution context running with any Hangfire task.
// Added because with asyncronous task, unrelated to requestes, there is no an alternative context to use with MongODM.
GlobalJobFilters.Filters.Add(new AsyncLocalContextHangfireFilter(AsyncLocalContext.Instance));
}
}
}
4 changes: 0 additions & 4 deletions src/MongODM.Hangfire/Tasks/HangfireTaskRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ public HangfireTaskRunner(
{
this.backgroundJobClient = backgroundJobClient;
this.mongODMOptions = mongODMOptions;

// Add a default execution context running with any Hangfire task.
// Added because with asyncronous task, unrelated to requestes, there is no an alternative context to use with MongODM.
GlobalJobFilters.Filters.Add(new AsyncLocalContextHangfireFilter(AsyncLocalContext.Instance));
}

// Methods.
Expand Down
1 change: 1 addition & 0 deletions src/MongODM/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ private static void AddHangfire(
// Add hangfire.
services.AddHangfire(options =>
{
options.UseMongODM();
options.UseMongoStorage(hangfireOptions.ConnectionString, hangfireOptions.StorageOptions);
});
}
Expand Down

0 comments on commit cc73928

Please sign in to comment.