HangFire的定时任务和Quartz.NET总结(三)Quartz 配置

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

用到了HangFire的定时任务app

这篇文章讲的很详细记录下   文章2  这篇更简单async

Quartz.NET总结(三)Quartz 配置

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!");
            });

        }