HangFire的定时任务

在一个Net Core需求中,需要在每天的凌晨三点去抓取两个电商仓库的剩余的每个料号的数量来写会自己的表中,

用到了HangFire的定时任务

这篇文章讲的很详细记录下

 public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            app.UseHangfireServer();
            app.UseHangfireDashboard("/hangfire",
                               new DashboardOptions()
                               {
                                   Authorization = new[] { new Code.HangfireMyAuthorizeFilter() }
                               });
        
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                //BackgroundJob.Enqueue<Inv.InventoryTransfer>(x => x.SyncTransfer("Commercial"));
                

            }
            else
            {
                //Bob add  设置每天凌晨三点获取一次即时库存
                string Cron_GetIMInventory = Configuration.GetSection("AppSettings").GetValue<string>("CronGetIMInventory");//获取到每天的凌晨三点钟               
                RecurringJob.AddOrUpdate<DS.PutOMSOrder>("PutOMSOrder", x =>
                            x.GetIMInventory(), Cron_GetIMInventory, System.TimeZoneInfo.Local);

                app.UseExceptionHandler("/Error");
                app.UseHsts();
            }           

            app.UseHttpsRedirection();
            app.UseStaticFiles();
            app.UseCookiePolicy();
            app.UseMvc();
            app.Run(async (context) =>
            {
               await context.Response.WriteAsync("Hello World!");
            });

        }

  

猜你喜欢

转载自www.cnblogs.com/ZkbFighting/p/10531451.html
今日推荐