
Код: Выделить всё
services.AddHangfire((serviceProvider, globalConfiguration) => globalConfiguration
.SetDataCompatibilityLevel(CompatibilityLevel.Version_170)
.UseRecommendedSerializerSettings()
.UseRedisStorage(redisConnectionString, redisStorageOptions)
.UseBatches()
.UseThrottling(ThrottlingAction.RetryJob, 1.Seconds())
.UseTagsWithRedis(new() { TagsListStyle = TagsListStyle.Dropdown }, redisStorageOptions)
.UseApplicationInsightsTelemetry(serviceProvider));
services.AddHangfireServer((provider, options) =>
{
options.Activator = new HangfireJobActivator(provider);
options.WorkerCount = Environment.ProcessorCount * 5;
options.HeartbeatInterval = 10.Seconds();
options.SchedulePollingInterval = 1.Seconds();
options.Queues = new[] { "critical", "default", "notifications" };
options.ServerName = Environment.MachineName;
});
Код: Выделить всё
backgroundJobClient.Enqueue(x => x.Perform(new(notificationMessage.Email, notificationMessage.Subject, notificationMessage.Body), null));
...
[Queue("notifications")]
[AutomaticRetry(Attempts = 3)]
public class EmailNotificationJob
{
readonly IServiceProvider _serviceProvider;
public EmailNotificationJob(IServiceProvider serviceProvider) => _serviceProvider = serviceProvider;
public async Task Perform(EmailNotificationJobOptions jobOptions, PerformContext? performContext)
{
...
}
}
Следует ли нам увеличить количество рабочих или как это сделать? мы работаем над решением этой проблемы?
Подробнее здесь: https://stackoverflow.com/questions/786 ... n-hangfire
Мобильная версия