Skip to content

Commit

Permalink
Use default activity kind
Browse files Browse the repository at this point in the history
  • Loading branch information
ejsmith committed Oct 28, 2024
1 parent 94176dc commit df961d4
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 11 deletions.
1 change: 1 addition & 0 deletions Foundatio.sln
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
samples\Directory.Build.props = samples\Directory.Build.props
NuGet.config = NuGet.config
README.md = README.md
.github\workflows\build-workflow.yml = .github\workflows\build-workflow.yml
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Samples", "Samples", "{A1DFF80C-113F-4FEC-84BB-1E3790FB410F}"
Expand Down
2 changes: 1 addition & 1 deletion src/Foundatio.Extensions.Hosting/Jobs/HostedJobService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private async Task ExecuteAsync(CancellationToken stoppingToken)

try
{
using var activity = FoundatioDiagnostics.ActivitySource.StartActivity("Job " + _jobOptions.Name, ActivityKind.Server);
using var activity = FoundatioDiagnostics.ActivitySource.StartActivity("Job " + _jobOptions.Name);

await runner.RunAsync(stoppingToken).AnyContext();
#if NET8_0_OR_GREATER
Expand Down
14 changes: 7 additions & 7 deletions src/Foundatio.Extensions.Hosting/Jobs/JobHostExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,29 +133,29 @@ public static IServiceCollection AddDistributedCronJob<T>(this IServiceCollectio
{
services.AddTransient<T>();
var jobOptionsBuilder = new ScheduledJobOptionsBuilder();
jobOptionsBuilder.Name(typeof(T).FullName).Distributed(true).CronSchedule(cronSchedule).JobFactory(sp => sp.GetRequiredService<T>());
jobOptionsBuilder.Name(typeof(T).FullName).Distributed().CronSchedule(cronSchedule).JobFactory(sp => sp.GetRequiredService<T>());
configureJobOptions?.Invoke(jobOptionsBuilder);
return services.AddCronJob(jobOptionsBuilder.Target);
}

public static IServiceCollection AddDistributedCronJob(this IServiceCollection services, string name, string cronSchedule, Func<IServiceProvider, CancellationToken, Task> action)
{
return services.AddCronJob(o => o.Name(name).Distributed(true).CronSchedule(cronSchedule).JobFactory(sp => new DynamicJob(sp, action)));
return services.AddCronJob(o => o.Name(name).Distributed().CronSchedule(cronSchedule).JobFactory(sp => new DynamicJob(sp, action)));
}

public static IServiceCollection AddDistributedCronJob(this IServiceCollection services, string name, string cronSchedule, Func<IServiceProvider, Task> action)
{
return services.AddCronJob(o => o.Name(name).Distributed(true).CronSchedule(cronSchedule).JobFactory(sp => new DynamicJob(sp, (xp, _) => action(xp))));
return services.AddCronJob(o => o.Name(name).Distributed().CronSchedule(cronSchedule).JobFactory(sp => new DynamicJob(sp, (xp, _) => action(xp))));
}

public static IServiceCollection AddDistributedCronJob(this IServiceCollection services, string name, string cronSchedule, Func<Task> action)
{
return services.AddCronJob(o => o.Name(name).Distributed(true).CronSchedule(cronSchedule).JobFactory(sp => new DynamicJob(sp, (_, _) => action())));
return services.AddCronJob(o => o.Name(name).Distributed().CronSchedule(cronSchedule).JobFactory(sp => new DynamicJob(sp, (_, _) => action())));
}

public static IServiceCollection AddDistributedCronJob(this IServiceCollection services, string name, string cronSchedule, Action<IServiceProvider, CancellationToken> action)
{
return services.AddCronJob(o => o.Name(name).Distributed(true).CronSchedule(cronSchedule).JobFactory(sp => new DynamicJob(sp, (xp, ct) =>
return services.AddCronJob(o => o.Name(name).Distributed().CronSchedule(cronSchedule).JobFactory(sp => new DynamicJob(sp, (xp, ct) =>
{
action(xp, ct);
return Task.CompletedTask;
Expand All @@ -164,7 +164,7 @@ public static IServiceCollection AddDistributedCronJob(this IServiceCollection s

public static IServiceCollection AddDistributedCronJob(this IServiceCollection services, string name, string cronSchedule, Action<CancellationToken> action)
{
return services.AddCronJob(o => o.Name(name).Distributed(true).CronSchedule(cronSchedule).JobFactory(sp => new DynamicJob(sp, (_, ct) =>
return services.AddCronJob(o => o.Name(name).Distributed().CronSchedule(cronSchedule).JobFactory(sp => new DynamicJob(sp, (_, ct) =>
{
action(ct);
return Task.CompletedTask;
Expand All @@ -173,7 +173,7 @@ public static IServiceCollection AddDistributedCronJob(this IServiceCollection s

public static IServiceCollection AddDistributedCronJob(this IServiceCollection services, string name, string cronSchedule, Action action)
{
return services.AddCronJob(o => o.Name(name).Distributed(true).CronSchedule(cronSchedule).JobFactory(sp => new DynamicJob(sp, (_, _) =>
return services.AddCronJob(o => o.Name(name).Distributed().CronSchedule(cronSchedule).JobFactory(sp => new DynamicJob(sp, (_, _) =>
{
action();
return Task.CompletedTask;
Expand Down
2 changes: 1 addition & 1 deletion src/Foundatio.Extensions.Hosting/Jobs/JobManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +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);
using var activity = FoundatioDiagnostics.ActivitySource.StartActivity("Job: " + job.Options.Name);
await job.StartAsync(cancellationToken).AnyContext();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ 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);
using var activity = FoundatioDiagnostics.ActivitySource.StartActivity("Scheduled Job: " + jobToRun.Options.Name);

if (await jobToRun.ShouldRunAsync())
await jobToRun.StartAsync(stoppingToken).AnyContext();
Expand Down
2 changes: 1 addition & 1 deletion src/Foundatio.TestHarness/Messaging/MessageBusTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public virtual async Task CanUseMessageOptionsAsync()

ActivitySource.AddActivityListener(listener);

using var activity = FoundatioDiagnostics.ActivitySource.StartActivity("Parent", ActivityKind.Internal);
using var activity = FoundatioDiagnostics.ActivitySource.StartActivity("Parent");
Assert.Equal(Activity.Current, activity);

var countdown = new AsyncCountdownEvent(1);
Expand Down

0 comments on commit df961d4

Please sign in to comment.