Skip to content

Commit

Permalink
Merge pull request #26 from Etherna/fix/MODM-76-hangire-filter-regist…
Browse files Browse the repository at this point in the history
…ration

Fixed MODM-76
  • Loading branch information
tmm360 authored May 21, 2021
2 parents bebef3f + cc73928 commit b14e308
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 b14e308

Please sign in to comment.