Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Hangfire Seperate Server setup with Abp #890


User avatar
0
paul lee created

Hi all,

I am very very new to Hangfire (I just know it is used to run jobs in the background) and this will be my first contact with it so please bear with me.

I am in the middle of a project where I need to generate some report and data export files in Excel and PDF. But our web server is quite busy so I need to off-load this document generation process to some other servers. I have read up on Hangfire's overview page that this can be configured as "Separate Server".

I can not vision how this is possible with Abp + Hangfire, can someone kindly explain generally how this can be done?

Thank you very much. Paul


2 Answer(s)
  • User Avatar
    0
    daws created

    Download hangfire project example from official hangfire website.

    It has multiple example : console, Windows service, ...

    for example, abp implementation in hangfire console :

    (which is just hangfire official example encapsulated in abpboostrapper :) ) (nb I use nlog, change it to your log provider)

    class Program
        {
            static void Main()
            {
                //Bootstrapping ABP system
                using (var bootstrapper = new AbpBootstrapper())
                {
                    IocManager.Instance.IocContainer.AddFacility<LoggingFacility>(f => f.UseNLog().WithConfig("NLog.config"));
    
                    bootstrapper.Initialize();
    
                    LogProvider.SetCurrentLogProvider(new ColouredConsoleLogProvider());
    
                    const string endpoint = "http://localhost:12345";
    
                    using (WebApp.Start<Startup>(endpoint))
                    {
                        Console.WriteLine();
                        Console.WriteLine("{0} Hangfire Server started.", DateTime.Now);
                        Console.WriteLine("{0} Dashboard is available at {1}/hangfire", DateTime.Now, endpoint);
                        Console.WriteLine();
                        Console.WriteLine("{0} Type JOB to add a background job.", DateTime.Now);
                        Console.WriteLine("{0} Press ENTER to exit...", DateTime.Now);
    
                        string command;
                        while ((command = Console.ReadLine()) != String.Empty)
                        {
                            if ("job".Equals(command, StringComparison.OrdinalIgnoreCase))
                            {
                                BackgroundJob.Enqueue(() => Console.WriteLine("{0} Background job completed successfully!", DateTime.Now.ToString()));
                            }
                        }
                    }
    
    
                }
    
            }
        }
    
  • User Avatar
    0
    paul lee created

    Thanks daws, you are the man.

    I have got it running and I am using the Console App route for now. Might want to move onto Windows Service later.

    Thank you very much.