HangfireIO / HangfireIO/Hangfire
Weird problem when running two methods inside the Enqueue
- Dominant language
- C#
- Stars
- 10.1k
- Forks
- 1.8k
- Avg merge
- 1h 19m
- Merged PRs (30d)
- 1
Description
I have an extension to enqueue my view models pointing to an implementation of an interface IBackgroundJob
this are my extensions methods
```C#
private static readonly ActivitySource activitySource = new("MC.Hangfire.Extensions");
public static string Enqueue(this T job, IBackgroundJobClient client)
{
return client.Enqueue>(ps => ps.AddTelemetry(null).EnqueueJob(null, job, JobCancellationToken.Null));
}
public static IBackgroundJob AddTelemetry(this IBackgroundJob job, PerformContext context)
{
using var activity = activitySource.StartActivity($"Start Job {typeof(T).FullName} id {context.BackgroundJob.Id}", ActivityKind.Server);
activity?.SetTag("JobId", context.BackgroundJob.Id);
activity?.SetTag("JobJson", Newtonsoft.Json.JsonConvert.SerializeObject(job));
activity?.SetTag("Job", Newtonsoft.Json.JsonConvert.SerializeObject(context.BackgroundJob.Job));
return job;
}
```
My problem is that the EnqueueJob method is called, but the AddTelemetry method is not called before, how can I Add the telemetry information before calling all of my jobs, but in the context of the jobs, and of course not adding this code in all of my enqueue methods?
EDIT:
I'll try to implement this with filters, not sure if it's the best way
Contributor guide
Assessment
This issue has not been assessed yet.