Skip to content

Commit

Permalink
Make sure job DI scope is disposed
Browse files Browse the repository at this point in the history
  • Loading branch information
ejsmith committed Oct 14, 2024
1 parent 0800eb6 commit 8fc7bfc
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public async Task StartAsync(CancellationToken cancellationToken = default)
try
{
using var activity = FoundatioDiagnostics.ActivitySource.StartActivity("Job " + Options.Name, ActivityKind.Server);
var scope = _serviceProvider.CreateScope();
await using var scope = _serviceProvider.CreateAsyncScope();

var job = Options.JobFactory(scope.ServiceProvider);
var result = await job.TryRunAsync(cancellationToken).AnyContext();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static partial class StartupExtensions
{
public static async Task<RunStartupActionsResult> RunStartupActionsAsync(this IServiceProvider serviceProvider, CancellationToken shutdownToken = default)
{
using var startupActionsScope = serviceProvider.CreateScope();
await using var startupActionsScope = serviceProvider.CreateAsyncScope();
var sw = Stopwatch.StartNew();
var logger = startupActionsScope.ServiceProvider.GetService<ILoggerFactory>()?.CreateLogger("StartupActions") ?? NullLogger.Instance;
var startupActions = startupActionsScope.ServiceProvider.GetServices<StartupActionRegistration>().ToArray();
Expand Down
2 changes: 1 addition & 1 deletion src/Foundatio/Jobs/JobRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public async Task<bool> RunAsync(CancellationToken cancellationToken = default)
{
try
{
var scope = _serviceProvider.CreateScope();
await using var scope = _serviceProvider.CreateAsyncScope();
var jobInstance = _options.JobFactory(scope.ServiceProvider);
await jobInstance.RunContinuousAsync(_options.Interval, _options.IterationLimit,
cancellationToken).AnyContext();
Expand Down

0 comments on commit 8fc7bfc

Please sign in to comment.