Exemplo n.º 1
0
 protected OrderNotifyTask(IDataLoader <OrderNotifyQueueListModel> dataLoader, TaskCron taskCron)
 {
     _taskCron = taskCron;
     if (_taskCron == null)
     {
         throw new ArgumentNullException("Task Cron", "没有通知任务的配置选项");
     }
     _queueNotifies = new Queue <OrderNotifyQueueListModel>();
     _dataLoader    = dataLoader;
 }
Exemplo n.º 2
0
        /// <summary>
        /// 添加计划
        /// </summary>
        /// <param name="task">通知任务配置实体</param>
        public void AddSchedule(TaskCron task)
        {
            var scheduleName = "SCH_ORDER_NOTIFY_" + task.NotifyTimes;

            RemoveSchedule(scheduleName);
            try
            {
                JobManager.AddJob(() =>
                {
                    if (!GlobalConfig.AllowReadDataFromDatabase)
                    {
                        //ScheduleAdding(Level.Error, "客户端已被禁用");
                        return;
                    }
                    //ScheduleAdding(Level.Info, string.Format("正在添加任务[{0}],周期[{1}]秒,是否从队列中删除数据[{2}]", scheduleName, task.Interval, task.IsDeleteData));
                    try
                    {
                        OrderNotifyTask notify;
                        var dataLoader = new DataLoader(); //new DataLoader();
                        if (!task.IsDeleteData)
                        {
                            notify = new OrderNotifyCommonTask(dataLoader, task);
                        }
                        else
                        {
                            notify = new OrderNotifyTaskWithDelete(dataLoader, task);
                        }
                        notify.OnDoingWork += Notify_OnDoingWork;
                        notify.RunJob();
                    }
                    catch (Exception ex)
                    {
                        var message = string.Format("执行订单通知任务时出错,原因:{0}", ex);
                        AddingScheduleError(message);
                        new DbLogger().Write(message);
                    }

                    //ScheduleAdding(Level.Info, string.Format("任务[{0}]添加成功,当前任务队列总任务[{1}]个.", scheduleName, GetAllScheduleCount));
                }, t => t.WithName(scheduleName).NonReentrant().ToRunNow().AndEvery(task.Interval).Seconds());
            }
            catch (Exception ex)
            {
                AddingScheduleError(string.Format("添加任务[{0}]时失败,原因:{1}", scheduleName, ex));
                //ScheduleAdding(Level.Error, string.Format("添加任务[{0}]时失败,原因:{1}", scheduleName, ex));
            }
        }
Exemplo n.º 3
0
        public void ConvertTaskCron()
        {
            if (string.IsNullOrEmpty(_taskCronConfigString))
            {
                return;
            }
            TaskCrons = new List <TaskCron>();

            //通知次数.间隔时间(秒).是否需要删除通知数据;通知次数.间隔时间(秒).是否需要删除通知数据

            /* 0.1.0;1.5.0;2.10.0;3.30.0;4.60.0;5.300.0;6.600.0;7.1800.0;8.3600.1;10.1.1;11.1.1;12.1.1
             */
            var configTaskList = _taskCronConfigString.Split(new[] { ";", "," }, StringSplitOptions.RemoveEmptyEntries);

            foreach (var task in configTaskList)
            {
                if (string.IsNullOrEmpty(task))
                {
                    ConvertError("任务配置选项为空!!!");
                    continue;
                }
                var config = task.Split(new[] { "." }, StringSplitOptions.RemoveEmptyEntries);
                if (config.Length != 3)
                {
                    ConvertError(string.Format("解析任务[{0}]配置选项格式错误,正确格式形如:[通知次数.间隔时间(秒).是否需要删除通知数据],多个任务以分号(;)或逗号(,)隔开", task));
                    continue;
                }
                var cron = new TaskCron
                {
                    NotifyTimes  = Convert.ToInt32(config[0]),
                    Interval     = Convert.ToInt32(config[1]),
                    IsDeleteData = config[2].Trim() == "1"
                };
                TaskCrons.Add(cron);
            }
        }
Exemplo n.º 4
0
 /// <summary>
 /// 通用的订单通知任务(本次通知完成后会删除数据库通知队列的数据)
 /// </summary>
 /// <param name="dataLoader">数据加载器接口实例</param>
 /// <param name="taskCron">订单通知的配置选项</param>
 public OrderNotifyTaskWithDelete(IDataLoader <OrderNotifyQueueListModel> dataLoader, TaskCron taskCron) : base(dataLoader, taskCron)
 {
 }
Exemplo n.º 5
0
 public OrderNotifyCommonTask(IDataLoader <OrderNotifyQueueListModel> dataLoader, TaskCron taskCron) : base(dataLoader, taskCron)
 {
 }