Hello,
Im developping a Addin for an Application which already starts a Hangfire instance on SQL Server.
This Server (with multiple queues) uses a .UseFilter
I can add an other Server (InMemory, and use a Filter)
services.AddSingleton((provider) => new BackgroundJobFactory(provider.GetRequiredService<IJobFilterProvider>()));
services.AddSingleton((provider) => new BackgroundJobStateChanger(provider.GetRequiredService<IJobFilterProvider>()));
services.AddSingleton((provider) =>
{
IJobFilterProvider filterProvider = provider.GetRequiredService<IJobFilterProvider>();
JobActivator activator = provider.GetRequiredService<JobActivator>();
return new ABackgroundJobPerformer(filterProvider, activator, null);
});
services.AddHangfire((serviceProvider, config) =>
{
config
.UseInMemoryStorage()
.UseActivator(new AIOAspNetCoreJobActivator(serviceProvider.GetService<IServiceScopeFactory>()))
.UseFilter(new AExportJobFilter(serviceProvider));
});
AutomaticRetryAttribute retrySettings = GlobalJobFilters.Filters
.OfType<JobFilter>()
.First((JobFilter f) => f.Instance is AutomaticRetryAttribute).Instance as AutomaticRetryAttribute;
retrySettings.Attempts = 3;
services.AddHangfireServer((serviceProvider, options) =>
{
options.SchedulePollingInterval = TimeSpan.FromMinutes(1.0);
options.Queues = new[] { "a-queue" };
options.WorkerCount = 5; // Adjust worker count as needed for A-Server
});
My job class:
[Queue("a-queue")]
public void PostUsersToAJob()
{
Debug.WriteLine("Posting");
}
My JobFilter class:
internal class AExportJobFilter : JobFilterAttribute, IElectStateFilter, IClientFilter
{
public void OnCreated(CreatedContext filterContext)
{
}
public void OnCreating(CreatingContext filterContext)
{
//Do something, Im not hit!
}
}
RecurringJob.AddOrUpdate<AJobs>(
nameof(AIOJobs.PostUsersToAJob),
"a-queue",
job => job.PostUsersToAJob(),
Cron.Minutely);
I the hangfire dashboard, i see the two server, with their Queues.
Also i see the job created, with in parentheses “a-queue”
I did expect, whilst using the .UseFilter
on my hangfile server with the a-queue
that this job will be handled by the AJobExportJobFilter
.
But, the job is being handled by the other, which is not under my control, JobFilter of the other party.
Did i miss something?