private void UpdateRank(RankKeywordInfo rankKeywordInfo) { DBKeywordTableAdapters.Keyword_RankTableAdapter kwRankAdapter = new DBKeywordTableAdapters.Keyword_RankTableAdapter(); kwRankAdapter.Connection.ConnectionString = connectionString; try { kwRankAdapter.Insert(rankKeywordInfo.KeywordID, rankKeywordInfo.Keyword, rankKeywordInfo.RankKeyword, rankKeywordInfo.DateCheck); } catch (Exception ex) { Log.Error(string.Format("ERROR with Keyword: {0}", rankKeywordInfo.Keyword), ex); } }
private void Run(string keyword) { this.Invoke(new Action(() => { lbCheckRestartProgram.Text = (checkRestartProgram + 1).ToString(); })); Job job = new Job(); RankKeywordInfo keywordInfo = new RankKeywordInfo() { KeywordID = GABIZ.Base.Tools.getCRC32(keyword), Keyword = keyword, RankKeyword = MyXpath.CheckRankKeyword("websosanh.vn", keyword, @"//div[@class='rc']/div[@class='s']/div/div[@class='f kv _SWb']"), DateCheck = DateTime.Now }; this.Invoke(new Action(() => { lbRank.Text = keywordInfo.RankKeyword.ToString(); })); //if (keywordInfo.RankKeyword == 9999) //{ // this.Invoke(new Action(() => // { // lbCheckRestartProgram.Text = "503 cmnr T_T"; // })); // Thread.Sleep(10000); // return false; //} //else //{ // job.Data = RankKeywordInfo.GetMess(keywordInfo); // jobClient.PublishJob(job); // checkRestartProgram++; // this.Invoke(new Action(() => // { // lbCheckRestartProgram.Text = checkRestartProgram.ToString(); // })); // Log.InfoFormat("{0}.Check success with: {1}", checkRestartProgram,keywordInfo.Keyword); // if (checkRestartProgram == limitRestartProgram) // { // return false; // } // else // return true; //} }
protected override void OnStart(string[] args) { try { connectionString = ConfigurationSettings.AppSettings["ConnectionString"]; string rabbitMQServerName = ConfigurationSettings.AppSettings["rabbitMQServerName"]; //worker string updateRankJobName = ConfigurationSettings.AppSettings["updateRankKeywordJobName"]; int workerCount = Convert.ToInt32(ConfigurationSettings.AppSettings["workerCount"]); workers = new Worker[workerCount]; rabbitMQServer = RabbitMQManager.GetRabbitMQServer(rabbitMQServerName); for (int i = 0; i < workerCount; i++) { var worker = new Worker(updateRankJobName, false, rabbitMQServer); workers[i] = worker; Task workerTask = new Task(() => { worker.JobHandler = (updateRankJob) => { try { //Do something here! RankKeywordInfo rk = new RankKeywordInfo(); rk = RankKeywordInfo.GetDataFromMessage(updateRankJob.Data); UpdateRank(rk); } catch (Exception ex) { Log.Error("Execute Job Error.", ex); } return(true); }; worker.Start(); }); workerTask.Start(); Log.InfoFormat("Worker {0} started", i); } } catch (Exception ex) { Log.Error("Start error", ex); throw; } }