From 874b546891eab4e4dd062bc3e6591ec2958c56c3 Mon Sep 17 00:00:00 2001 From: "Eric J. Smith" Date: Fri, 25 Oct 2024 13:47:10 -0500 Subject: [PATCH] Change job activities to include cache calls --- src/Foundatio.Extensions.Hosting/Jobs/JobManager.cs | 2 ++ src/Foundatio.Extensions.Hosting/Jobs/ScheduledJobRunner.cs | 1 - src/Foundatio.Extensions.Hosting/Jobs/ScheduledJobService.cs | 4 ++++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Foundatio.Extensions.Hosting/Jobs/JobManager.cs b/src/Foundatio.Extensions.Hosting/Jobs/JobManager.cs index beee03ed..948217df 100644 --- a/src/Foundatio.Extensions.Hosting/Jobs/JobManager.cs +++ b/src/Foundatio.Extensions.Hosting/Jobs/JobManager.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -201,6 +202,7 @@ public async Task RunJobAsync(string jobName, CancellationToken cancellationToke if (job == null) throw new ArgumentException("Job not found.", nameof(jobName)); + using var activity = FoundatioDiagnostics.ActivitySource.StartActivity("Job: " + job.Options.Name, ActivityKind.Server); await job.StartAsync(cancellationToken).AnyContext(); } diff --git a/src/Foundatio.Extensions.Hosting/Jobs/ScheduledJobRunner.cs b/src/Foundatio.Extensions.Hosting/Jobs/ScheduledJobRunner.cs index 471c5691..19758c5b 100644 --- a/src/Foundatio.Extensions.Hosting/Jobs/ScheduledJobRunner.cs +++ b/src/Foundatio.Extensions.Hosting/Jobs/ScheduledJobRunner.cs @@ -142,7 +142,6 @@ public async Task StartAsync(CancellationToken cancellationToken = default) { try { - using var activity = FoundatioDiagnostics.ActivitySource.StartActivity("Job " + Options.Name, ActivityKind.Server); await using var scope = _serviceProvider.CreateAsyncScope(); var job = Options.JobFactory(scope.ServiceProvider); diff --git a/src/Foundatio.Extensions.Hosting/Jobs/ScheduledJobService.cs b/src/Foundatio.Extensions.Hosting/Jobs/ScheduledJobService.cs index 2738ae84..59045e08 100644 --- a/src/Foundatio.Extensions.Hosting/Jobs/ScheduledJobService.cs +++ b/src/Foundatio.Extensions.Hosting/Jobs/ScheduledJobService.cs @@ -1,7 +1,9 @@ using System; +using System.Diagnostics; using System.Threading; using System.Threading.Tasks; using Foundatio.Extensions.Hosting.Startup; +using Foundatio.Messaging; using Foundatio.Utility; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; @@ -35,6 +37,8 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken) { foreach (var jobToRun in _jobManager.Jobs) { + using var activity = FoundatioDiagnostics.ActivitySource.StartActivity("Scheduled Job: " + jobToRun.Options.Name, ActivityKind.Server); + if (await jobToRun.ShouldRunAsync()) await jobToRun.StartAsync(stoppingToken).AnyContext(); }