Have implemented hangfire for background jobs.
Firstly being wondering if this reduces resources utilization since my iis cpu and ram usage is high.
Am using recurring jobs. Every 5 minutes.
Seems every time I run the project, a new recurring job is created , how can I avoid this ?
11 Answer(s)
-
0
Hello, I don't think this question is related to ABP but still, there is some information I want to share with you ✌️
Firstly being wondering if this reduces resources utilization since my iis cpu and ram usage is high.
Unfortunately, I don't know much about the ISS.
Seems every time I run the project, a new recurring job is created , how can I avoid this ?
Hangfire methods allow calling with a delay. For instance:
BackgroundJob.Schedule( () => Console.WriteLine("Hello, world"), TimeSpan.FromDays(1));
See more: https://docs.hangfire.io/en/latest/background-methods/calling-methods-with-delay.html
-
0
The issue is each time the app re starts it add a new recurring jobs instead of updating existing
-
0
Hi,
I think you need background worker instead of background jobs
https://docs.abp.io/en/abp/latest/Background-Workers-Hangfire
-
0
Below is my class worker class and how am calling it
public override void OnApplicationInitialization(ApplicationInitializationContext context) { context.AddBackgroundWorkerAsync<SyncLeavePlans>(); }
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Volo.Abp.BackgroundJobs; using Volo.Abp.BackgroundWorkers; using Volo.Abp.Domain.Repositories; using Volo.Abp.Modularity; using Volo.Abp.MultiTenancy; using Volo.Abp.Threading; using Volo.Saas.Tenants; using System.Linq; using System.Linq.Dynamic.Core; using System.Linq.Expressions; using Volo.Abp.BackgroundWorkers.Hangfire; using Hangfire; using Volo.Abp.DependencyInjection; using Volo.Abp.Uow; using System.Threading; namespace API.Integrations { public interface ISyncLeavePlans : IHangfireBackgroundWorker { } [DependsOn( typeof(AbpBackgroundWorkersModule), typeof(AbpMultiTenancyModule), typeof(AbpBackgroundJobsModule) )] [ExposeServices(typeof(ISyncLeavePlans))] public class SyncLeavePlans : HangfireBackgroundWorkerBase, ISyncLeavePlans { [Obsolete] public SyncLeavePlans( ) { RecurringJobId = "ISyncLeavePlans"; CronExpression = Cron.MinuteInterval(5); } [UnitOfWork] public override async Task DoWorkAsync(CancellationToken cancellationToken) { Logger.LogInformation("Starting:..."); Logger.LogInformation("Completed:..."); } } }
After running the project, we see the below two jobs. Executed in milliseconds.
-
0
-
0
@liangshiwei as per the logs you've shared. Every seconds the recurring job is running and executing.
It should every 5 minutes only. That's the issue.
-
0
-
0
Let me run some tests
-
0
ok
-
0
By the way am using this to push data to a 3rd party system. Is it the recommended way ?
-
0
Hi,
I think there is no problem.