本文介绍了现在随着视觉开始执行石英调度区间24小时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我创建了一个爬虫,获取来自我对之前定义的其他网站的消息,所以我用石英来运行background.the调度任务定义像这样的:I create a crawler that gets the news from the other website that i defined before for it ,so i use quartz to run a task in background.the schedule is defined like this :public class JobBackground : IJob { public void Execute(IJobExecutionContext context) { for (int j = 1; j <= 920; j++) { NewsRepository newsRepository = new NewsRepository(); GoyaAgent Goyaagent = new GoyaAgent(); Task<List<NewsContent>> lst = Goyaagent.parsing("http://www.gooyait.com/page/"+j); List<NewsContent> enresult = lst.Result; foreach (NewsContent newsContent in enresult) { News newnews = new News(); newnews.Subject = newsContent.Title; newnews.NewsDate = DateTime.Now; newnews.NewsBrief = newsContent.abs; newnews.NewsText = newsContent.Content; newnews.ShowOnSlide = "Yes"; newnews.GroupId = 1049; newnews.NewsImageSmall = newsContent.Img; newnews.NewsImageBig = newsContent.Img; newnews.Reference = newsContent.Url; newnews.UserId = "3"; newnews.Visible = "Yes"; newnews.ViewCounter = 0; newsRepository.Add(newnews); if (newsRepository.FindBy(i => i.Reference == newsContent.Url).Count() == 0) newsRepository.Save(); } } } }的解析功能: public async Task<List<NewsContent>> parsing(string newsArchive) { List<NewsContent> lstResult = new List<NewsContent>(); try { HttpClient http = new HttpClient(); var response = await http.GetByteArrayAsync(newsArchive); String source = Encoding.GetEncoding("utf-8").GetString(response, 0, response.Length - 1); source = WebUtility.HtmlDecode(source); HtmlDocument resultat = new HtmlDocument(); resultat.LoadHtml(source); List<HtmlNode> toftitle = resultat.DocumentNode.Descendants().Where (x => (x.Name == "div" && x.Attributes["class"] != null && x.Attributes["class"].Value.Contains("main-col"))).ToList(); var li = toftitle[0].Descendants().Where (x => (x.Name == "div" && x.Attributes["class"] != null && x.Attributes["class"].Value.Contains("base-box blog-post"))).ToList(); foreach (var item in li) { NewsContent newsContent = new NewsContent(); newsContent.Url = item.Descendants("a").ToList()[0].GetAttributeValue("href", null); newsContent.Img = item.Descendants("img").ToList()[0].GetAttributeValue("src", null); newsContent.Title = item.Descendants("h2").ToList()[0].InnerText; newsContent.abs = item.Descendants("p").ToList()[0].InnerText; //finding main news content var response1 = await http.GetByteArrayAsync(newsContent.Url); String source1 = Encoding.GetEncoding("utf-8").GetString(response1, 0, response1.Length - 1); source1 = WebUtility.HtmlDecode(source1); HtmlDocument resultat1 = new HtmlDocument(); resultat1.LoadHtml(source1); HtmlNode doc = resultat1.DocumentNode.SelectSingleNode("//div[@class='entry-content']"); HtmlNode node = doc.SelectSingleNode("//div[@class='yasr-visitor-votes']"); if (node != null) node.ParentNode.RemoveChild(node); HtmlNode node1 = doc.SelectSingleNode("//div[@class='post-tags']"); if (node1 != null) node1.ParentNode.RemoveChild(node1); HtmlNode node2 = doc.SelectSingleNode("//div[@class='mom-social-share ss-horizontal border-box']"); if (node2 != null) node2.ParentNode.RemoveChild(node2); HtmlNode node3 = doc.SelectSingleNode("//script|//style"); if (node3 != null) node3.ParentNode.RemoveChild(node3); newsContent.Content = doc.InnerHtml; lstResult.Add(newsContent); } } catch (Exception e) { } return lstResult; }日程安排与此code开头:The schedule starts with this code : public class JobScheduler { public static void Start() { IScheduler scheduler = StdSchedulerFactory.GetDefaultScheduler(); scheduler.Start(); IJobDetail job = JobBuilder.Create<JobBackground>().Build(); ITrigger trigger = TriggerBuilder.Create().StartNow() .WithDailyTimeIntervalSchedule (s => s.WithIntervalInHours(24) .OnEveryDay() .StartingDailyAt(TimeOfDay.HourAndMinuteOfDay(0, 0)) ) .Build(); scheduler.ScheduleJob(job, trigger); } }有几个问题:当我运行这个code中的code从不因为执行ITrigger触发= TriggerBuilder.Create()。StartNow(),所以我必须等待24小时看到的结果,为什么?When i run this code the code never executed because ofITrigger trigger = TriggerBuilder.Create().StartNow() so i have to wait for 24 hours to see the result why ?和第二个问题,当我上传code到Web服务器这是行不通的。为什么?And the second problem ,when i upload the code to the web server it doesn't work .why ?推荐答案尝试更新你的方法,如下所示:Try to update your method as shown below:public class JobScheduler{ public static void Start() { IScheduler scheduler = StdSchedulerFactory.GetDefaultScheduler(); scheduler.Start(); IJobDetail job = JobBuilder.Create<JobBackground>().Build(); ITrigger trigger = TriggerBuilder.Create() .WithIdentity("trigger1", "group1") .StartNow() .WithSchedule(CronScheduleBuilder .DailyAtHourAndMinute(0,0) .WithMisfireHandlingInstructionFireAndProceed() //MISFIRE_INSTRUCTION_FIRE_NOW .InTimeZone(TimeZoneInfo.FindSystemTimeZoneById("GTB Standard Time")) //(GMT+02:00) //https://alexandrebrisebois.wordpress.com/2013/01/20/using-quartz-net-to-schedule-jobs-in-windows-azure-worker-roles/ ) .Build(); scheduler.ScheduleJob(job, trigger); }}关于第二个问题,这个问题是关系到 IIS 而非调度 Quartz.NET ,迟发型等。另一方面,有很多解决的方法在网上公布,但只有其中的一些工作。我认为,没有必要应用许多的配置设置。只要安装保持活动的服务,为IIS 6.0 / 7.5 在服务器上,你发布你的应用程序,并享受。然后,您发布的应用将是以后应用程序池回收,IIS /应用重启等活的希望这有助于...Regarding to the second issue, the problem is related to IIS rather than the schedulers Quartz.NET, Hangfire, etc. On the other hand, there are lots of solution methods posted on the web, but only some of them is working. In my opinion, there is no need to apply lots of configuration settings. Just install Keep Alive Service For IIS 6.0/7.5 on the server to which you publish your application and enjoy. Then your published application will be alive after application pool recycling, IIS/Application restarting, etc. Hope this helps... 更新:这里是完全工作code我用IIS上月没有任何问题。在另一方面,根据引发的问题IIS,看看我的回答投放Quartz.net调度不火的工作/触发器一旦部署。的的Global.asax:的protected void Application_Start(){ JobScheduler.Start();}的 EmailJob.cs:的using Quartz;public class EmailJob : IJob{ public void Execute(IJobExecutionContext context) { SendEmail(); }}的 JobScheduler.cs:的using Quartz;using Quartz.Impl;public class JobScheduler{ public static void Start() { IScheduler scheduler = StdSchedulerFactory.GetDefaultScheduler(); scheduler.Start(); IJobDetail job = JobBuilder.Create<EmailJob>().Build(); ITrigger trigger = TriggerBuilder.Create() .WithIdentity("trigger1", "group1") //.StartAt(new DateTime(2015, 12, 21, 17, 19, 0, 0)) .StartNow() .WithSchedule(CronScheduleBuilder .WeeklyOnDayAndHourAndMinute(DayOfWeek.Monday, 10, 00) //.WithMisfireHandlingInstructionDoNothing() //Do not fire if the firing is missed .WithMisfireHandlingInstructionFireAndProceed() //MISFIRE_INSTRUCTION_FIRE_NOW .InTimeZone(TimeZoneInfo.FindSystemTimeZoneById("GTB Standard Time")) //(GMT+02:00) ) .Build(); scheduler.ScheduleJob(job, trigger); }} 这篇关于现在随着视觉开始执行石英调度区间24小时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-23 00:05
查看更多