Base solution for your next web application
Open Closed

Hangfire to perform recurrent tasks at specific time #4425


User avatar
0
soonjoo created

Hello team,

I have set up hangfire, and I can access the dashboard, however, how do I set up a recurring job so that it executes everyday at 12 midnight?

I have read the documentation and created a class which inherit BackgroundJob

public class DailyDataAggregatorJob : BackgroundJob<DailyDataAggregatorJobArgs>, ITransientDependency
    {
        public DailyDataAggregatorJob()
        {
        }

        [UnitOfWork]
        public override void Execute(DailyDataAggregatorJobArgs args)
        {
            Logger.Info("Inside DailyDataAggregatorJob");
        }
    }

however, where should I put the code the start this recurring job and tell them to execute it daily? according to the hangfire documentation I am supposed to add this line of code somewhere

RecurringJob.AddOrUpdate(() => Console.Write("Easy!"), Cron.Daily);

I have checked the abp documentation on background jobs but it doesn't demonstrate this.

thanks!

Markdown is supported
Copy & paste or drag & drop images (max 30 MB per image)

3 Answer(s)
  • User Avatar
    0
    aaron created
    Support Team

    How: Duplicate of #4084@f49f2625-f54c-4486-a701-ce50d5e16ed5

    <cite>alirizaadiyahsi: </cite>

    Abp.HangFire.AspNetCore is already referenced in AspNetZero. You can use it directly. After you apply this step: https://aspnetzero.com/Documents/Development-Guide-Core#background-jobs-and-hangfire then you can also use Hangfire API. Just write Hangfire code.

    Where: Duplicate of #2645@b7f111ed-945f-4b50-9722-d62c0b9a22be

    <cite>Hozkar: </cite> I'm trying to define my Recurring Jobs in the Postinitialize Method of my Web Module

    Also see the second topic for solutions to potential issues.

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    soonjoo created

    Hi @aaron,

    Thank you for your reply, I had managed to get my code working after looking at the example code in those topics!

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    aaron created
    Support Team

    That's great :)

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)