Hi,
Can you give me an example code for job creation with hangfire. Which triggered every minute and log "Hello World" to log file. And starting with application startup.
Thanks
13 Answer(s)
-
0
You can take a look at this demo: AbpHangfireConsoleApp
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
I dont understand that code. There are some integrations at Zero Modula with Hangfire and i want to use that.
I need simple code.
Muhittin
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
I have an action named Scan which is triggered from a button. I want to schedule this action.
[AbpAuthorize(AppPermissions.Pages_TrackedHosts_Scan)] public async Task Scan(EntityDto input) { .. .. .. }
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
you can create periodic background job and add to the background queue via
BackgroundJobManager.See aspnetboilerplate#background-works
To make your background jobs run using Hangfire Integration.
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
To enable hangfire integration for AspNetZero.
Configure these hangfire setup.
Web.Core Project
https://github.com/aspnetzero/aspnet-zero-core/blob/29ce1d485ad7955591fa8a97d1d446340c5986e4/aspnet-core/src/MyCompanyName.AbpZeroTemplate.Web.Core/AbpZeroTemplateWebCoreModule.cs#L78Web.Host Project
https://github.com/aspnetzero/aspnet-zero-core/blob/29ce1d485ad7955591fa8a97d1d446340c5986e4/aspnet-core/src/MyCompanyName.AbpZeroTemplate.Web.Host/Startup/Startup.cs#L185Web.Mvc Project
https://github.com/aspnetzero/aspnet-zero-core/blob/f72d4bf9ced778e06265f1c415a8553b10cbaf3d/aspnet-core/src/MyCompanyName.AbpZeroTemplate.Web.Mvc/Startup/Startup.cs#L161Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
Settings are ok. I added the following lines to web.mvc startup file.
string cronExp = "1 * * * *"; EntityDto a = new EntityDto(); a.Id = 1; RecurringJob.AddOrUpdate<ITrackedHostsAppService>(x => x.Scan(a), cronExp);
It is running every minute but got this error. Not user logged in. Because this Scan method is need authorization.
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
1
Limitations
More than one background jobs in a single transaction isn't supported by Hangfire. Because, Hangfire does not participate the current transaction. It does not use the ambient transaction (TransactionScope).
The background job will not be able to retrieve current user id & tenant id. You need to pass these as the parameters to the background job
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
Is there any example about how to pass login parameters to background job.
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
All background and hangfire jobs failed due to current user not logged error. I need a solution for background jobs. Background job must call thefollowing service method which has need authorization like below;
[AbpAuthorize(AppPermissions.Pages_TrackedHosts_Scan)] public async Task Scan(EntityDto input) {
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
1
so don't use the method
Scan()because it's made to be executed by a user which hasPages_TrackedHosts_Scanpermission. Create a new method wich doesn't have any permissions required.Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
Rather than creating a new method without AbpAuthorization, can we make the hangfire jobs to run under a particular role always e.g. Admin or User?
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
Any luck on this?
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
@rajalla, see here: getting Hangfire to work in Zero
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image)