コード例 #1
0
        /// <summary>
        /// Thực thi chạy cập nhật trạng thái sản phẩm theo từ web quảng cáo
        /// </summary>
        /// <param name="schedules"></param>
        public void RunScheduleWeb(List <CronJobProductStatu> schedules)
        {
            _log.Info("Begin execute the scheduler for website");
            _log.Info(String.Format("Run Schedule Web - Number Schedule: {0:N}", schedules.Count));

            var scheduleUpdate = new List <CronJobProductStatu>();
            var index          = 0;

            foreach (var schedule in schedules)
            {
                // Đếm số lượng thực thi
                index++;

                // Thực thi post API cập nhật thông tin trạng thái sản phẩm
                var response = postAPI(schedule);
                // Lấy thông tin trạng thái lịch trình sau khi thực thi post API
                var scheduleDone = checkResponse(schedule, response);

                scheduleUpdate.Add(scheduleDone);
                _log.Info(String.Format("{0:N0} - Run Schedule Web - {1}", index, JsonConvert.SerializeObject(scheduleDone)));

                Thread.Sleep(500);
            }

            CronJobController.updateScheduleProductStatus(scheduleUpdate);
        }
コード例 #2
0
        public override void Execute()
        {
            try
            {
                _log.Info("Begin excute post API for the websites");

                // Nếu cron job được yêu cầu dưng lại thì sẽ không sử lý nữa
                if (isPause())
                {
                    _log.Info("Run Schedule Web - Cron Job Pause.");
                    return;
                }

                var schedules = CronJobController.getScheduleProductStatus(_website, (int)CronJobStatus.Scheduled, 80);
                _log.Info(String.Format("Run Schedule - Number Schedule: {0:N}", schedules.Count));

                if (schedules.Count > 0)
                {
                    // Lock các dữ liệu chuẩn bị start
                    schedules = schedules.Select(x =>
                    {
                        x.Status = (int)CronJobStatus.Start;
                        return(x);
                    })
                                .ToList();
                    CronJobController.updateScheduleProductStatus(schedules);

                    // Chạy post API
                    RunScheduleWeb(schedules);
                }

                _log.Info("End excute post API for the websites");
            }
            catch (ThreadAbortException)
            {
                Thread.ResetAbort();
            }
        }