Base solution for your next web application
Open Closed

Move HangFire to Service #1908


User avatar
0
andmattia created

I try to move Hangfire(HF in rest of post) to service because I think in a Cluser eviroment it's more stable and scalable but I find some issue.

The step that I do is: disable on web module the HF

//Configuration.BackgroundJobs.UseHangfire(configuration =>
 //           {
  //              configuration.GlobalConfiguration.UseSqlServerStorage(queueName);
   //         });

After that in web proj I have a problem on Startup.cs beacuse at

app.UseHangfireDashboard("/hangfire", new DashboardOptions
            {
                Authorization = new[] { new    AbpHangfireAuthorizationFilter(AppPermissions.Pages_Administration_HangfireDashboard) }
            });

HangFire is not enable

My service is composed by (I share my code)

[DependsOn(typeof(AbpHangfireModule))]
    public class AbpHangFireService : AbpModule
    {
        public override void PreInitialize()
        {
            Database.SetInitializer<clayDbContext>(null);

            var queueName = "Default";

            Configuration.BackgroundJobs.UseHangfire(configuration =>
            {
                SqlServerStorageExtensions.UseSqlServerStorage(
                    (IGlobalConfiguration) configuration.GlobalConfiguration, queueName);
            });

        }

        public override void Initialize()
        {
            IocManager.RegisterAssemblyByConvention(Assembly.GetExecutingAssembly());
        }
    }

and in service class

private readonly AbpBootstrapper bootstrapper;
        public Service1()
        {
            InitializeComponent();
            bootstrapper = AbpBootstrapper.Create<AbpHangFireService>();
            
                bootstrapper.IocManager.IocContainer
                    .AddFacility<LoggingFacility>(f => f.UseAbpLog4Net()
                        .WithConfig("log4net.config")
                    );

        }

        protected override void OnStart(string[] args)
        {

            bootstrapper.Initialize();
        }

        protected override void OnStop()
        {
            bootstrapper.Dispose();
        }

So my service start en log on txt file but if i dsable in web app I see only server on service if I re-enable it I see 2 sever app&service also if i disable in web app I cann't open dashboard is it possibile to bind web app to HF service. and If backgorundjob start on my service where service search dll (like core) in service bin or app bin?


3 Answer(s)
  • User Avatar
    0
    andmattia created

    Small Update.

    After read (another time) documentation I set Job

    public override void PreInitialize()
        {
            Configuration.BackgroundJobs.IsJobExecutionEnabled = false;
        }
    

    [http://www.aspnetboilerplate.com/Pages/Documents/Background-Jobs-And-Workers#disabling-job-execution])

    So now I've only service registered on HF. I've re enable HF on startup & dashboard and I can see the HF dashboard my job work fine. At the moment Notification not work fine because I don't see any NotificationDistributionJob

  • User Avatar
    0
    andmattia created

    Notification Issue

    after Backgroud job try to send a client notification not fire but notification will send to user and if after notification correctly send to user i refresh (fire F5) I see my bell with +1 notification.

  • User Avatar
    0
    andmattia created

    ok! Thks to @hikalkan suppurt finally service work and I'm able to send back notification to webapp.

    Later I update my git hub project