Exemplo n.º 1
0
        static void ScheduleJobs(string instance)
        {
            var scheduler = Schedulers.Get(instance);

            foreach (var behaviorType in BehaviorTypes.All())
            {
                var jobName = "Recompute similarity matrix (" + behaviorType + ")";
                var config  = JobConfig.Load(instance, jobName);
                if (config == null)
                {
                    config = new JobConfig
                    {
                        JobName   = jobName,
                        Interval  = TimeSpan.FromHours(24),
                        StartTime = new TimeOfDay(2, 0)
                    };
                }

                var job = new RecomputeSimilarityMatrixJob();

                scheduler.Schedule(jobName, job, config.Interval, config.StartTime, new Dictionary <string, string>
                {
                    { "BehaviorType", behaviorType }
                });
            }
        }
        protected override bool EntityTaskHandler(WelfareRemindModel model, bool mustBackup = true)
        {
            if (null != model)
            {
                TimeSpan duetime = model.ApplyStartTime.AddMinutes(-Startup.WelfareConfig.BeforeRemindMinutes).Subtract(DateTime.Now);    //延迟执行时间(以毫秒为单位)

                if (duetime.Ticks < 0)
                {
                    duetime = TimeoutZero;
                }

                System.Threading.Timer timer = new System.Threading.Timer(new TimerCallback(Execute), model, duetime, TimeoutInfinite);

                if (mustBackup)
                {
                    //复制到备份区以防数据丢失
                    BackBeforeDone(model.WelfareID, model);
                }

                //输出消息
                string message = string.Format("〖福利:{0}〗将在{1}天{2}小时{3}分{4}秒后提醒用户参与报名", model.WelfareID, duetime.Days, duetime.Hours, duetime.Minutes, duetime.Seconds);

                RunLogger(message);

                Schedulers.Add(model.WelfareID, timer);

                return(true);
            }

            return(false);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 执行单次请求并返回是否需要继续指示信号
        /// </summary>
        /// <returns></returns>
        protected override bool SingleRequest()
        {
            var levelList = EnumExtensions.GetEnumDesc <CacheLevel>(typeof(CacheLevel));

            foreach (var level in levelList)
            {
                //更新周期(以毫秒为单位)
                TimeSpan period = new TimeSpan(0);

                var levelConfig = Startup.CacheMaintainConfigs.FirstOrDefault(p => p.Level == level.EnumItem);

                if (null != levelConfig && levelConfig.PeriodTime > 0)
                {
                    int time = levelConfig.PeriodTime;

                    switch (levelConfig.TimeOption)
                    {
                    case SysEnums.CacheTimeOption.Day: period = new TimeSpan(time, 0, 0, 0); break;

                    case SysEnums.CacheTimeOption.Hour: period = new TimeSpan(0, time, 0, 0); break;

                    case SysEnums.CacheTimeOption.Minute: period = new TimeSpan(0, 0, time, 0); break;
                    }

                    ScheduleClocker clocker = new ScheduleClocker(new TimeSpan(0), period, Execute, level.EnumItem);

                    Schedulers.Add(level.Name, clocker);
                }
            }

            return(true);
        }
        protected override bool EntityTaskHandler(ReservationOrderLateReceiveModel model, bool mustBackup = true)
        {
            if (null != model)
            {
                TimeSpan duetime = model.WorkerFinishTime.AddDays(Startup.AppointConfig.EndServiceWaitUserDays).Subtract(DateTime.Now);    //延迟执行时间(以毫秒为单位)

                if (duetime.Ticks < 0)
                {
                    duetime = TimeoutZero;
                }

                System.Threading.Timer timer = new System.Threading.Timer(new TimerCallback(Execute), model, duetime, TimeoutInfinite);

                if (mustBackup)
                {
                    //复制到备份区以防数据丢失
                    BackBeforeDone(model.OrderID, model);
                }

                //输出消息
                string message = string.Format("〖预约订单(ID:{0})〗在{1}天{2}小时{3}分{4}秒后未确认服务完成系统将自动确认服务完成", model.OrderID, duetime.Days, duetime.Hours, duetime.Minutes, duetime.Seconds);

                RunLogger(message);

                Schedulers.Add(model.OrderID, timer);

                return(true);
            }

            return(false);
        }
        protected override bool EntityTaskHandler(LegworkOrderTimeoutModel model, bool mustBackup = true)
        {
            if (null != model)
            {
                DateTime lastTime = model.CreateTime.AddSeconds(Startup.LegworkGlobalConfig.OrderTimeout);

                TimeSpan duetime = lastTime.Subtract(DateTime.Now);    //延迟执行时间(以毫秒为单位)

                if (duetime.Ticks < 0)
                {
                    duetime = TimeoutZero;
                }

                System.Threading.Timer timer = new System.Threading.Timer(new TimerCallback(Execute), model, duetime, TimeoutInfinite);

                if (mustBackup)
                {
                    //复制到备份区以防数据丢失
                    BackBeforeDone(model.OrderID, model);
                }

                //输出消息
                string message = string.Format("〖跑腿订单(ID:{0})〗在{1}天{2}小时{3}分{4}秒后没有员工接单,系统将自动取消订单", model.OrderID, duetime.Days, duetime.Hours, duetime.Minutes, duetime.Seconds);

                RunLogger(message);

                Schedulers.Add(model.OrderID, timer);

                return(true);
            }

            return(false);
        }
        protected override bool EntityTaskHandler(VisitingOrderLateNoPaymentModel model, bool mustBackup = true)
        {
            if (null != model)
            {
                TimeSpan duetime = model.LastPaymentTime.Subtract(DateTime.Now);    //延迟执行时间(以毫秒为单位)

                if (duetime.Ticks < 0)
                {
                    duetime = TimeoutZero;
                }

                System.Threading.Timer timer = new System.Threading.Timer(new TimerCallback(Execute), model, duetime, TimeoutInfinite);

                if (mustBackup)
                {
                    //复制到备份区以防数据丢失
                    BackBeforeDone(model.OrderID, model);
                }

                //输出消息
                string message = string.Format("〖上门订单(ID:{0})〗在{1}天{2}小时{3}分{4}秒后未付款系统将自动取消订单", model.OrderID, duetime.Days, duetime.Hours, duetime.Minutes, duetime.Seconds);

                RunLogger(message);

                Schedulers.Add(model.OrderID, timer);

                return(true);
            }

            return(false);
        }
Exemplo n.º 7
0
        protected override bool EntityTaskHandler(WelfareLotteryModel model, bool mustBackup = true)
        {
            if (null != model)
            {
                TimeSpan duetime = model.LotteryTime.Subtract(DateTime.Now);    //延迟执行时间(以毫秒为单位)

                if (duetime.Ticks < 0)
                {
                    duetime = TimeoutZero;
                }

                System.Threading.Timer timer = new System.Threading.Timer(new TimerCallback(Execute), model, duetime, TimeoutInfinite);

                if (mustBackup)
                {
                    //复制到备份区以防数据丢失
                    BackBeforeDone(model.WelfareID, model);
                }

                //输出消息
                string message = string.Format("〖福利:{0}〗将于{2}天{3}小时{4}分{5}秒后({1})开奖", model.Name, model.LotteryTime.ToString("yyyy/MM/dd HH:mm:ss"), duetime.Days, duetime.Hours, duetime.Minutes, duetime.Seconds);

                RunLogger(message);

                Schedulers.Add(model.WelfareID, timer);

                return(true);
            }

            return(false);
        }
Exemplo n.º 8
0
        protected override bool EntityTaskHandler(MallOrderLateReceiveModel model, bool mustBackup = true)
        {
            if (null != model)
            {
                DateTime lastTime = model.ShipTime.AddDays(Startup.B2COrderConfig.WaitReceiptGoodsDays);

                TimeSpan duetime = lastTime.Subtract(DateTime.Now);    //延迟执行时间(以毫秒为单位)

                if (duetime.Ticks < 0)
                {
                    duetime = TimeoutZero;
                }

                System.Threading.Timer timer = new System.Threading.Timer(new TimerCallback(Execute), model, duetime, TimeoutInfinite);

                if (mustBackup)
                {
                    //复制到备份区以防数据丢失
                    BackBeforeDone(model.OrderID, model);
                }

                //输出消息
                string message = string.Format("〖精品汇订单(ID:{0})〗在{1}天{2}小时{3}分{4}秒后未收货系统将自动确认收货", model.OrderID, duetime.Days, duetime.Hours, duetime.Minutes, duetime.Seconds);

                RunLogger(message);

                Schedulers.Add(model.OrderID, timer);

                return(true);
            }

            return(false);
        }
Exemplo n.º 9
0
        public void Dispose()
        {
            this.jobDetail = null;

            if (this.quartzScheduler != null)
            {
                this.Stop();
                if (!this.quartzScheduler.IsShutdown)
                {
                    this.quartzScheduler.Shutdown();
                }

                this.quartzScheduler = null;
                for (int i = 0; i < 3; i++)
                {
                    Thread.Sleep(200);
                }
            }

            if (Schedulers.ContainsKey(this.name))
            {
                Schedulers.Remove(this.name);
            }

            this.Trigger = null;

            if (schedulers != null)
            {
                schedulers.Clear();
            }
            this.jobDetail = null;
        }
Exemplo n.º 10
0
        public static void Initialize(string instance)
        {
            var defaultBehaviorWeights = new Dictionary <string, float>
            {
                { BehaviorTypes.View, .5f },
                { BehaviorTypes.AddToCart, .7f },
                { BehaviorTypes.Purchase, 1f }
            };

            foreach (var behaviorType in BehaviorTypes.All())
            {
                BehaviorStores.Register(instance, behaviorType, new SqlceBehaviorStore(instance, behaviorType));

                float weight = defaultBehaviorWeights[behaviorType];
                var   config = BehaviorConfig.Load(instance, behaviorType);
                if (config != null)
                {
                    weight = config.Weight;
                }

                var matrix = new SqlceSimilarityMatrix(instance, behaviorType, "Similarity_" + behaviorType);
                SimilarityMatrixes.Register(instance, behaviorType, matrix);
                RelatedItemsProviders.Register(instance, new ItemToItemRelatedItemsProvider(matrix), weight);
            }

            BehaviorReceivers.Set(instance, new BufferedBehaviorReceiver(new BehaviorReceiver(instance), 1000, TimeSpan.FromSeconds(5)));
            RecommendationEngines.Register(instance, CreateRecommendationEngines(instance));

            Schedulers.Start(instance);
            ScheduleJobs(instance);
        }
        protected override bool EntityTaskHandler(MallOrderNoPaymentModel model, bool mustBackup = true)
        {
            //对象不为null
            if (null != model)
            {
                DateTime lastTime = model.NeedPayTime ?? model.CreateTime.AddMinutes(Startup.B2COrderConfig.WaitPaymentMinutes);

                TimeSpan duetime = lastTime.Subtract(DateTime.Now);    //延迟执行时间

                if (duetime.Ticks < 0)
                {
                    duetime = TimeoutZero;
                }

                System.Threading.Timer timer = new System.Threading.Timer(new TimerCallback(Execute), model, duetime, TimeoutInfinite);

                if (mustBackup)
                {
                    //复制到备份区以防数据丢失
                    BackBeforeDone(model.OrderID, model);
                }

                //输出消息
                string message = string.Format("〖精品汇订单(ID:{0})〗在{1}天{2}小时{3}分{4}秒后未付款系统将自动取消订单", model.OrderID, duetime.Days, duetime.Hours, duetime.Minutes, duetime.Seconds);

                RunLogger(message);

                Schedulers.Add(model.OrderID, timer);

                return(true);
            }

            return(false);
        }
Exemplo n.º 12
0
        public async void Stop()
        {
            Schedulers.Remove(baseUrl);

            await scheduler.Shutdown(false);

            Logger.GetLogger(baseUrl).Info(baseUrl + " feed scheduler stoped");
        }
Exemplo n.º 13
0
 public static FeedScheduler GetSecheduler(string baseUrl)
 {
     if (!Schedulers.ContainsKey(baseUrl))
     {
         throw new Exception("feed scheduler is no instantiation!");
     }
     return(Schedulers[baseUrl]);
 }
Exemplo n.º 14
0
 public Scheduler(ITrigger trigger = null)
 {
     this.jobDetail = JobBuilder.Create <EventRaiserJob>()
                      .WithIdentity(this.name.ToString(), "Scheduler")
                      .Build();
     Schedulers.Add(this.name, this);
     this.Trigger = trigger;
 }
Exemplo n.º 15
0
        protected override void Execute(object state)
        {
            var model = state as MallOrderLateReceiveModel;

            if (null == model)
            {
                return;
            }

            try
            {
                //从备份区将备份删除
                DeleteBackAfterDone(model.OrderID);

                var lastOrder = MallOrderProvider.GetOrder(model.OrderID);

                if (null == lastOrder)
                {
                    throw new CustomException(string.Format("〖精品汇订单(ID:{0})〗信息已不存在!", model.OrderID));
                }

                if (lastOrder.OrderStatus != (int)B2COrderStatus.WaitingReceipt)
                {
                    throw new CustomException(string.Format("〖精品汇订单(ID:{0})〗状态已发生变更,不能自动完成收货!", lastOrder.OrderID));
                }

                if (model.ShipTime != model.ShipTime)
                {
                    throw new CustomException(string.Format("〖精品汇订单(ID:{0})〗不能确定发货时间,不能自动完成收货!", lastOrder.OrderID));
                }

                //结算并自动收货
                var settlement = new MallOrderSettlementCenter(model.OrderID, true);
                settlement.Execute();

                string message = string.Empty;

                if (settlement.Success)
                {
                    message = string.Format("〖精品汇订单(ID:{0}/{1})〗自动确认收货完成!", lastOrder.OrderID, lastOrder.ProductInfo);
                }
                else
                {
                    message = string.Format("〖精品汇订单(ID:{0}/{1})〗自动确认收货失败,原因:{2}", lastOrder.OrderID, lastOrder.ProductInfo, settlement.ErrorMessage);
                }

                RunLogger(message);
            }
            catch (Exception ex)
            {
                this.OnThrowException(ex);
            }
            finally
            {
                Schedulers.Remove(model.OrderID);
            }
        }
Exemplo n.º 16
0
        public void SchdlMdl_UsuarioString_ReturnTrue()
        {
            //Act
            var prueba = new Schedulers();

            prueba.Usuario = "Usuario de prueba";

            //Assert
            Assert.IsType <string>(prueba.Usuario);
        }
Exemplo n.º 17
0
        public void SchdlMdl_IsActiveBool_ReturnTrue()
        {
            //Act
            var prueba = new Schedulers();

            prueba.IsActive = false;

            //Assert
            Assert.IsType <bool>(prueba.IsActive);
        }
Exemplo n.º 18
0
        public static void Dispose(string instance)
        {
            RecommendationEngines.RemoveEngines(instance);

            Schedulers.Stop(instance);
            BehaviorReceivers.Remove(instance);
            BehaviorStores.Remove(instance);
            SimilarityMatrixes.Remove(instance);
            RelatedItemsProviders.RemoveProviders(instance);
        }
Exemplo n.º 19
0
        public void SchdlMdl_SchedulerIdInt_ReturnTrue()
        {
            //Act
            var prueba = new Schedulers();

            prueba.SchedulerId = 584;

            //Assert
            Assert.IsType <Int32>(prueba.SchedulerId);
        }
Exemplo n.º 20
0
        public override sealed void Clear()
        {
            foreach (IGlyphComponent component in Components)
            {
                Schedulers.UnplanComponent(component);
            }

            _keyedComponents.Clear();

            base.Clear();
        }
Exemplo n.º 21
0
        /// <summary>
        /// 释放资源
        /// </summary>
        /// <param name="disposing"></param>
        public override void Dispose(bool disposing)
        {
            if (!m_disposed)
            {
                if (disposing)
                {
                    Schedulers.Dispose();
                }

                m_disposed = true;
            }
        }
Exemplo n.º 22
0
        protected override void Execute(object state)
        {
            var model = state as LegworkAutoConfirmTimeModel;

            if (null == model)
            {
                return;
            }

            try
            {
                //从备份区将备份删除
                DeleteBackAfterDone(model.OrderID);

                var lastOrder = LegworkOrderProvder.GetLegworkOrder(model.OrderID);

                if (null == lastOrder)
                {
                    throw new CustomException(string.Format("〖跑腿订单(ID:{0})〗信息已不存在!", model.OrderID));
                }

                if (lastOrder.Status != (int)LegworkOrderStatus.Delivered)
                {
                    throw new CustomException(string.Format("〖跑腿订单(ID:{0})〗状态已发生变更,不能自动完成收货!", lastOrder.OrderID));
                }

                //if (model.ShipTime != model.ShipTime) throw new CustomException(string.Format("订单(编号{0})不能确定发货时间,不能自动完成收货!", lastOrder.OrderCode));

                //结算并自动收货
                var settlement = LegworkOrderProvder.UpdateAutoConfirmTime(lastOrder);

                string message = string.Empty;

                if (settlement.Result)
                {
                    message = string.Format("〖跑腿订单(ID:{0})〗自动确认收货完成!", lastOrder.OrderID);
                }
                else
                {
                    message = string.Format("〖跑腿订单(ID:{0})〗自动确认收货失败!", lastOrder.OrderID);
                }

                RunLogger(message);
            }
            catch (Exception ex)
            {
                this.OnThrowException(ex);
            }
            finally
            {
                Schedulers.Remove(model.OrderID);
            }
        }
Exemplo n.º 23
0
        /// <summary>
        /// Clear all collections
        /// </summary>
        internal void ClearAllCollections()
        {
            var filter = new BsonDocument();

            Schedulers.DeleteMany(filter);
            Calendars.DeleteMany(filter);
            Triggers.DeleteMany(filter);
            Jobs.DeleteMany(filter);
            PausedTriggerGroups.DeleteMany(filter);
            PausedJobGroups.DeleteMany(filter);
            BlockedJobs.DeleteMany(filter);
        }
Exemplo n.º 24
0
        public ActionResult JobConfig(string jobName)
        {
            var schedule = Schedulers.Get(CurrentInstance.Name).GetSchedule(jobName);

            return(JsonNet(new JobConfigModel
            {
                JobName = jobName,
                Interval = (int)schedule.Interval.TotalMinutes,
                StartHour = schedule.StartTime.Hour,
                StartMinute = schedule.StartTime.Mintue
            }).UsingClientConvention());
        }
        protected override void Execute(object state)
        {
            var model = state as ReservationOrderLateReceiveModel;

            if (null == model)
            {
                return;
            }

            try
            {
                //从备份区将备份删除
                DeleteBackAfterDone(model.OrderID);

                var lastOrder = AppointOrderProvider.GetAppointOrder(model.OrderID);

                if (null == lastOrder)
                {
                    throw new CustomException(string.Format("〖预约订单(ID:{0})〗信息已不存在!", model.OrderID));
                }

                if (lastOrder.Status != (int)ReservationServiceOrderStatus.MerchantServiceDone)
                {
                    throw new CustomException(string.Format("〖预约订单(ID:{0})〗状态已发生变更,不能自动确认服务完成!", lastOrder.OrderID));
                }

                //结算并自动收货
                var settlement = new ReservationOrderSettlementCenter(model.OrderID, true);
                settlement.Execute();

                string message = string.Empty;

                if (settlement.Success)
                {
                    message = string.Format("〖预约订单(ID:{0})〗自动确认服务完成!", lastOrder.OrderID);
                }
                else
                {
                    message = string.Format("〖预约订单(ID:{0})〗自动确认服务完成失败,原因:{1}", lastOrder.OrderID, settlement.ErrorMessage);
                }

                RunLogger(message);
            }
            catch (Exception ex)
            {
                this.OnThrowException(ex);
            }
            finally
            {
                Schedulers.Remove(model.OrderID);
            }
        }
Exemplo n.º 26
0
        public override sealed bool Remove(IGlyphComponent item)
        {
            if (!Contains(item) || !base.Remove(item))
            {
                return(false);
            }

            _keyedComponents.Remove(x => x.Value == item);

            Schedulers.UnplanComponent(item);

            return(true);
        }
Exemplo n.º 27
0
        public void JobConfig(JobConfigModel model)
        {
            Kooboo.Commerce.Recommendations.Engine.Jobs.JobConfig.Update(CurrentInstance.Name, new JobConfig
            {
                JobName   = model.JobName,
                Interval  = TimeSpan.FromMinutes(model.Interval),
                StartTime = new TimeOfDay(model.StartHour, model.StartMinute)
            });

            var scheduler = Schedulers.Get(CurrentInstance.Name);

            scheduler.Reschedule(model.JobName, TimeSpan.FromMinutes(model.Interval), new TimeOfDay(model.StartHour, model.StartMinute));
        }
        protected override void Execute(object state)
        {
            var model = state as LegworkOrderTimeoutModel;

            if (null == model)
            {
                return;
            }

            try
            {
                //从备份区将备份删除
                DeleteBackAfterDone(model.OrderID);

                var lastOrder = LegworkOrderProvder.GetLegworkOrder(model.OrderID);

                if (null == lastOrder)
                {
                    throw new CustomException(string.Format("〖跑腿订单(ID:{0})〗信息已不存在!", model.OrderID));
                }

                if (lastOrder.Status != (int)LegworkOrderStatus.WaitingHandle)
                {
                    throw new CustomException(string.Format("〖跑腿订单(ID:{0})〗状态已发生变更,不能取消订单!", lastOrder.OrderID));
                }

                //结算并自动收货
                var settlement = LegworkOrderProvder.UpdateOrderTimeout(lastOrder);

                string message = string.Empty;

                if (settlement.Result)
                {
                    message = string.Format("〖跑腿订单(ID:{0})〗自动取消订单完成!", lastOrder.OrderID);
                }
                else
                {
                    message = string.Format("〖跑腿订单(ID:{0})〗自动取消订单失败!", lastOrder.OrderID);
                }

                RunLogger(message);
            }
            catch (Exception ex)
            {
                this.OnThrowException(ex);
            }
            finally
            {
                Schedulers.Remove(model.OrderID);
            }
        }
        protected override void Execute(object state)
        {
            var model = state as MallOrderNoPaymentModel;

            if (null == model)
            {
                return;
            }

            try
            {
                //从备份区将备份删除
                DeleteBackAfterDone(model.OrderID);

                var lastOrder = MallOrderProvider.GetOrder(model.OrderID);

                if (null == lastOrder)
                {
                    throw new CustomException(string.Format("〖精品汇订单(ID:{0})〗信息已不存在!", model.OrderID));
                }

                if (lastOrder.OrderStatus != (int)B2COrderStatus.WaitingPayment)
                {
                    throw new CustomException(string.Format("〖精品汇订单(ID:{0})〗状态发生变更,不能自动取消订单", lastOrder.OrderID));
                }

                //自动取消订单
                bool cancelSuccess = MallOrderProvider.AutoCancelOrder(lastOrder.OrderID).Result;

                string message = string.Empty;

                if (cancelSuccess)
                {
                    message = string.Format("〖精品汇订单(ID:{0}/{1})〗因超时未付款,系统已自动取消订单!", lastOrder.OrderID, lastOrder.ProductInfo);
                }
                else
                {
                    message = string.Format("〖精品汇订单(ID:{0}/{1})〗因超时未付款,系统自动取消订单时操作失败!", lastOrder.OrderID, lastOrder.ProductInfo);
                }

                RunLogger(message);
            }
            catch (Exception ex)
            {
                this.OnThrowException(ex);
            }
            finally
            {
                Schedulers.Remove(model.OrderID);
            }
        }
Exemplo n.º 30
0
        public Task <TResult> ProcessQuery <TQuery, TResult>(TQuery query) where TQuery : IAsyncQuery <object>
        {
            IScheduler scheduler;

            if (Schedulers.TryGetValue(typeof(TQuery), out scheduler))
            {
                return(scheduler.Run(() => _queryBus.ProcessQuery <TQuery, TResult>(query)));
            }
            if (DefaultScheduler != null)
            {
                return(DefaultScheduler.Run(() => _queryBus.ProcessQuery <TQuery, TResult>(query)));
            }
            return(_queryBus.ProcessQuery <TQuery, TResult>(query));
        }