예제 #1
0
 /// <summary>
 /// 根据用户重新载入任务
 /// </summary>
 /// <returns></returns>
 public bool ReloadByUserId(params int[] userIds)
 {
     try
     {
         var syncService = new TradeSyncService(_constr);
         tradeSyncContextService.BuildContext(userIds);
         var array = tradeSyncContextService.SyncContext;
         array.Context.ForEach(x =>
         {
             var tmp = syncList.Find(y => y.UserId == x.UserId);
             if (tmp != null)
             {
                 RecurringJob.RemoveIfExists(tmp.TaskId);
             }
             else
             {
                 x.TaskId = Guid.NewGuid().ToString();
                 syncList.Add(x);
             }
             RecurringJob.AddOrUpdate(x.TaskId, () => syncService.DoJob(x.Shops), Cron.HourInterval(x.SyncPeriodHours));
         });
         return(true);
     }
     catch (Exception ex)
     {
         FrameworkLog.LogModel.LogHelper.WriteErrorLog($"根据用户重新载入任务", ex);
         return(false);
     }
 }
예제 #2
0
        /// <summary>
        /// 初始化调度计划
        /// </summary>
        public bool Start()
        {
            try
            {
                FrameworkLog.LogModel.LogHelper.WriteInfoLog($"开始启动任务调度");
                tradeSyncContextService.BuildContext();
                syncList = tradeSyncContextService.SyncContext.Context;

                syncList.ForEach(x =>
                {
                    var syncService = new TradeSyncService(_constr);
                    x.TaskId        = Guid.NewGuid().ToString();
                    RecurringJob.AddOrUpdate(x.TaskId, () => syncService.DoJob(x.Shops), Cron.HourInterval(x.SyncPeriodHours));
                });
                FrameworkLog.LogModel.LogHelper.WriteInfoLog($"启动任务调度完毕");
                return(true);
            }
            catch (Exception ex)
            {
                FrameworkLog.LogModel.LogHelper.WriteErrorLog($"启动任务调度失败", ex);
                return(false);
            }
        }