コード例 #1
0
        public void Process(ScheduledTaskContext context)
        {
            if (context.Task.TaskType != "AssociativyTagNodeUpdate") return;

            Renew(true);

            var graphs = _tagGraphManager.GetTagGraphs();

            if (graphs.Count() == 0) return;

            foreach (var node in _contentManager.Query<AssociativyTagNodePart>("AssociativyTagNode").Join<AssociativyTagNodePartRecord>().List())
            {
                try
                {
                    // This throws an exception if the tag was deleted. Is there a better way for this? This is a bit ugly...
                    if (node.Tag.TagName != node.As<AssociativyNodeLabelPart>().Label)
                    {
                        node.As<AssociativyNodeLabelPart>().Label = node.Tag.TagName;
                    }
                }
                catch (Exception ex)
                {
                    if (ex.IsFatal()) throw;

                    // The tag was deleted
                    _contentManager.Remove(node.ContentItem);
                    foreach (var graph in graphs)
                    {
                        graph.ConnectionManager.DeleteFromNode(node);
                    }
                }
            }
        }
コード例 #2
0
        public void Sweep() {
            var taskEntries = _repository.Fetch(x => x.ScheduledUtc <= _clock.UtcNow)
                .Select(x => new { x.Id, Action = x.TaskType })
                .ToArray();

            foreach (var taskEntry in taskEntries) {
                _transactionManager.RequireNew();

                try {
                    // fetch the task
                    var taskRecord = _repository.Get(taskEntry.Id);

                    // another server or thread has performed this work before us
                    if (taskRecord == null) {
                        continue;
                    }

                    // removing record first helps avoid concurrent execution
                    _repository.Delete(taskRecord);

                    var context = new ScheduledTaskContext {
                        Task = new Task(_contentManager, taskRecord)
                    };

                    // dispatch to standard or custom handlers
                    foreach (var handler in _handlers) {
                        handler.Process(context);
                    }
                }
                catch (Exception ex) {
                    Logger.Warning(ex, "Unable to process scheduled task #{0} of type {1}", taskEntry.Id, taskEntry.Action);
                    _transactionManager.Cancel();
                }
            }
        }
コード例 #3
0
ファイル: LockFileCleaner.cs プロジェクト: kanujhun/myblog
        public void Process(ScheduledTaskContext context)
        {
            if (context.Task.TaskType != TaskType) return;

            Renew(true);
            CleanUp();
        }
コード例 #4
0
 public void Process(ScheduledTaskContext context){
     if (context.Task.TaskType == "SwitchTheme"){
         _themeService.EnableThemeFeatures("Offline");
         _siteThemeService.SetSiteTheme("Offline");
     }
     else if (context.Task.TaskType == "ResetSite"){
         Logger.Information("start reseting site data at {2} utc", context.Task.ScheduledUtc);
         var factory = _sessionFactoryHolder.GetSessionFactory();
         using (var session = factory.OpenSession()){
             var connection = session.Connection;
             var dialect = Dialect.GetDialect(_sessionFactoryHolder.GetConfiguration().Properties);
             var meta = dialect.GetDataBaseSchema((DbConnection)connection);
             var tables = meta.GetTables(null, null, null, null);
             try{
                 foreach (DataRow dr in tables.Rows){
                     _schemaBuilder.DropTable(dr["TABLE_NAME"].ToString());
                 }
                 ExecuteOutSql("~/Modules/Coevery.SiteReset/Sql/create.sql");
             }
             catch (Exception ex){
                 Logger.Warning(ex, "reset site error");
             }
         }
     }
 }
        public void Process(ScheduledTaskContext context)
        {
            if (context.Task.TaskType != TaskType) return;

            Renew(true);

            for (int i = 0; i < ItemBatch; i++)
            {
                var job = _jobManager.TakeJob(Industry);

                if (job == null) return;

                var jobContext = job.Context<GraphJobContext>();

                var graphs = _graphManager.FindGraphs(new GraphContext { ContentTypes = new[] { jobContext.ItemType } });

                foreach (var graph in graphs.Where(graph => _settingsService.Get(graph.Name).ProcessInternalLinks))
                {
                    foreach (var url in jobContext.LinkedUrls)
                    {
                        var route = _aliasService.Get(url.TrimStart('/'));
                        if (route != null && (route.ContainsKey("Id") || route.ContainsKey("threadId"))) // threadId is hack for NGM.Forum threads
                        {
                            var target = route.ContainsKey("Id") ? _contentManager.Get(Convert.ToInt32(route["Id"])) : _contentManager.Get(Convert.ToInt32(route["threadId"]));
                            if (target != null && graph.ContentTypes.Contains(target.ContentType))
                            {
                                graph.Services.ConnectionManager.Connect(jobContext.ItemId, target.Id);
                            }
                        }
                    }
                }

                _jobManager.Done(job);
            }
        }
コード例 #6
0
        public void Process(ScheduledTaskContext context)
        {
            if (context.Task.TaskType != TaskType) return;

            using (var lockFile = _lockResolve.Value)
            {
                if (!lockFile.TryAcquire(TaskType)) return;

                Renew(true);

                foreach (var repository in _bitbucketService.RepositoryDataRepository.Table)
                {
                    try
                    {
                        if (repository.WasChecked()) _bitbucketService.CheckChangesets(repository.Id);
                    }
                    catch (Exception ex)
                    {
                        if (ex.IsFatal()) throw;

                        Logger.Error(ex, "Exception when processing checking changesets on Bitbucket for the repository " + repository.AccountName + "/" + repository.Slug);
                    }
                }
            }
        }
コード例 #7
0
        public void Sweep() {


            try
            {
                while (true)
                {
                    ScheduledTaskRecord taskToRun = new ScheduledTaskRecord();
                    using (var scope = new TransactionScope(TransactionScopeOption.Suppress, new TransactionOptions() { IsolationLevel = IsolationLevel.Serializable }))
                    {
                        var taskRecord = _repository.Fetch(x => x.ScheduledUtc <= _clock.UtcNow).FirstOrDefault();
                        // another server or thread has performed this work before us
                        if (taskRecord == null)
                        {
                            break;
                        }
                        _repository.Copy(taskRecord, taskToRun);
                        _repository.Delete(taskRecord);
                        _repository.Flush();
                        scope.Complete();
                    }

                    //using (ISession _session = _sessionLocator.For(typeof(ScheduledTaskRecord)))
                    //{
                    //    using (var tx = _session.BeginTransaction(System.Data.IsolationLevel.ReadUncommitted))
                    //    {
                    using (var scope = new TransactionScope(TransactionScopeOption.Required))
                    {
                        var context = new ScheduledTaskContext
                        {
                            Task = new Task(_contentManager, taskToRun)
                        };

                        // dispatch to standard or custom handlers
                        foreach (var handler in _handlers)
                        {
                            handler.Process(context);
                        }
                        scope.Complete();
                    }
                
                    _contentManager.Flush();
                    _contentManager.Clear();

                }
            }
            catch (Exception ex)
            {
                Logger.Warning(ex, "Unable to process scheduled task.");

                //TODO: handle exception to rollback dedicated xact, and re-delete task record. 
                // does this also need some retry logic?
                //Maybe put in taskToRun back in if retry parameter included?
            }
            
        }
コード例 #8
0
        // This method will be called periodically (every minute) with the current task context. Because of this we have to check if the
        // current task is ours. (BTW this way the same taks handler can handle multiple tasks.)
        // Remember that although we scheduled the task to be run 3 minutes in the future it won't run in exactly 3 minutes, but practically
        // in a one minute time frame after the scheduled time, the worst case being one minute after what we scheduled. Also if the Orchard 
        // instance is torn down before that (e.g. by an AppPool recycle) the task may run at an even later date. Don't rely on backgroud tasks
        // runnin exactly on schedule!
        void IScheduledTaskHandler.Process(ScheduledTaskContext context)
        {
            // Not our task
            if (context.Task.TaskType != TaskType) return;

            // Check out in the debugger: this should be called every 3 minutes.
            _eventHandler.ScheduledTaskFired(new ScheduledTaskFiredContext { TaskType = TaskType });

            CreateTaskIfNew(true); // Renewing the task
        }
コード例 #9
0
        public void Process(ScheduledTaskContext context) {
            if (context.Task.TaskType == "Publish") {
                Logger.Information("Publishing item #{0} version {1} scheduled at {2} utc",
                    context.Task.ContentItem.Id,
                    context.Task.ContentItem.Version,
                    context.Task.ScheduledUtc);

                _contentManager.Publish(context.Task.ContentItem);
            }
        }
コード例 #10
0
        public void Process(ScheduledTaskContext context) {
            var taskType = context.Task.TaskType;
            if (Constants.DefaultEventNames.Contains(taskType)) {

                var contentItem = context.Task.ContentItem;
                _workflowManager.TriggerEvent(taskType, contentItem,
                    () => new Dictionary<string, object>{
                        { "Content", contentItem }
                    });
            }
        }
コード例 #11
0
        public void Process(ScheduledTaskContext context) {
            if (context.Task.TaskType == "TriggerRule") {
                Logger.Information("Triggering Rule item #{0} version {1} scheduled at {2} utc",
                                   context.Task.ContentItem.Id,
                                   context.Task.ContentItem.Version,
                                   context.Task.ScheduledUtc);

                var scheduledActionTask = context.Task.ContentItem.As<ScheduledActionTaskPart>();

                _rulesManager.ExecuteActions(scheduledActionTask.ScheduledActions.Select(x => x.ActionRecord), new Dictionary<string, object>());
            }
        }
コード例 #12
0
        public void Process(ScheduledTaskContext context)
        {
            if (context.Task.TaskType == PublishMenuTaskManager.PublishTaskType) {
                if (context.Task.ContentItem.Has<TitlePart>() && context.Task.ContentItem.ContentType == "Menu") {
                    Logger.Information("Publishing menu '{0}', version {1} scheduled at {2} utc",
                                       context.Task.ContentItem.As<TitlePart>().Title,
                                       context.Task.ContentItem.Version,
                                       context.Task.ScheduledUtc);

                    _menus.PublishMenu(context.Task.ContentItem.Id, context.Task.ContentItem.VersionRecord.Id);
                    _orchardServices.ContentManager.Flush();
                }
            }
        }
コード例 #13
0
        public void Process(ScheduledTaskContext context)
        {
            if (context.Task.TaskType != TaskType) return;

            Renew(true);

            // Clean up old events
            var cleanUpCount = _repository.Table.Count() - 1000;
            if (cleanUpCount <= 0) return;
            foreach (var record in _repository.Table.OrderBy(record => record.Id).Take(cleanUpCount))
            {
                _repository.Delete(record);
            }
        }
コード例 #14
0
ファイル: ADTaskHandler.cs プロジェクト: kubo08/Orchard
 //planovane tasky
 /// <summary>
 /// runs scheduled task to synchronize users with active directory.
 /// </summary>
 /// <param name="context">The context.</param>
 public void Process(ScheduledTaskContext context)
 {
     if (context.Task.TaskType == TaskType)
     {
         try
         {
             RunJob(null);
         }
         catch (DbException e)
         {
             Logger.Error(string.Format("Nastala chyba pri praci z databazou, pravdepodobne sa uz vykonava jeden update. {0}", e.Message));
         }
     }
 }
コード例 #15
0
 public void Process(ScheduledTaskContext context)
 {
     if (context.Task.TaskType == "SychronizeUser")
     {
         IUser user = context.Task.ContentItem.As<IUser>();
         this._webStoreServices.UsingClient(
             c =>
             {
                 Customer customer = c.CustomerClient.GetCustomer(user.UserName, false);
                 if(customer != null)
                 {
                     c.CustomerClient.UpdateCustomer(customer.CustomerId, user.UserName, user.Email, true);
                 }
             }
         );
     }
 }
コード例 #16
0
ファイル: ScheduledTaskHandler.cs プロジェクト: rgardler/dpp
 public void Process(ScheduledTaskContext context)
 {
     if (context.Task.TaskType != TaskType) return;
     Logger.Debug(DateTime.UtcNow + "> Starting Process");
     try {
         JobsSync();
     }
     catch (Exception e)
     {
         Logger.Error(e, e.Message);
     }
     finally
     {
         var nextTaskDate = DateTime.UtcNow.AddMinutes(5);
         ScheduleNextTask(nextTaskDate);
     }
 }
コード例 #17
0
        public void Process(ScheduledTaskContext context)
        {
            if (context.Task.TaskType == TASK_TYPE_PROCESS_MODEL && context.Task.ContentItem != null)
            {
                try
                {                    
                    _blockModelService.ProcessModel(context.Task.ContentItem);
                }
                catch (Exception e)
                {
                    this.Logger.Error(e, e.Message);
                }
                finally
                {

                }
            }
        }
コード例 #18
0
 public void Process(ScheduledTaskContext context)
 {
     if (context.Task.TaskType == TASK_TYPE_EMAIL && context.Task.ContentItem != null)
     {
         try
         {
             var em = context.Task.ContentItem.As<EmailPart>();
             _userService.EmailUsers(em.Recipients.SplitStringArray(), em.Subject, em.Body, false);
         }
         catch (Exception e)
         {
             this.Logger.Error(e, e.Message);
         }
         finally
         {
           
         }
     }
 }
コード例 #19
0
 public void Process(ScheduledTaskContext context)
 {
     if (context.Task.TaskType == TASK_TYPE_MAIL_API && context.Task.ContentItem != null)
     {
         try
         {
             var p = context.Task.ContentItem.As<MailApiPart>();
             _mailApi.ProcessApiRequest(p);
         }
         catch (Exception e)
         {
             this.Logger.Error(e, e.Message);
         }
         finally
         {
           
         }
     }
 }
コード例 #20
0
        public void Process(ScheduledTaskContext context)
        {
            var settings = this.orchardServices.WorkContext.CurrentSite.As<DisqusSettingsPart>();

            if (!settings.SyncComments)
                return;

            if (context.Task.TaskType == TaskType)
            {
                try
                {
                    this.updateService.UpdateCommentsFromDisqus();
                }
                catch (Exception e)
                {
                    this.Logger.Error(e, e.Message);
                }

                this.ScheduleNextTask(settings.SyncInterval);
            }
        }
コード例 #21
0
 public void Process(ScheduledTaskContext context)
 {
     if (context.Task.TaskType == TASK_TYPE)
     {
         try
         {
             Logger.Information("----------------------------- Check Expired promotions task started --------------------------------");
             _promotionService.CheckExpiredPromotions();
         }
         catch (Exception e)
         {
             this.Logger.Error("Error occured when running Check Expired promotions task ---------------- >" + e.ToString(), e.Message);
         }
         finally
         {
             Logger.Information("----------------------------- Check Expired promotions task finished --------------------------------");
             var nextTaskDate = DateTime.Today.Date.AddDays(1).AddMinutes(1);
             ScheduleNextTask(TimeZoneInfo.ConvertTimeToUtc(nextTaskDate, TimeZoneInfo.Local));
         }
     }
 }
コード例 #22
0
 public void Process(ScheduledTaskContext context)
 {
     if (context.Task.TaskType == TASK_TYPE)
     {
         try
         {
             Logger.Information("----------------------------- Send Finished Campaign after 1 day to Seller task started --------------------------------");
             _teeyootMessagingService.SendOrderShipped3DaysToBuyer();
         }
         catch (Exception e)
         {
             this.Logger.Error("Error occured when running Send Finished Campaign after 1 day to Seller task ---------------- >" + e.ToString(), e.Message);
         }
         finally
         {
             Logger.Information("----------------------------- Send Finished Campaign after 1 day to Seller task finished --------------------------------");
             var nextTaskDate = DateTime.Today.Date.AddDays(1).AddMinutes(1);
             ScheduleNextTask(TimeZoneInfo.ConvertTimeToUtc(nextTaskDate, TimeZoneInfo.Local));
         }
     }
 }
コード例 #23
0
        public void Process(ScheduledTaskContext context) {
            var part = context.Task.ContentItem.As<ConfigurationPart>();
            if (part == null)
                return;

            var name = GetName(part.Title());
            if (context.Task.TaskType != name)
                return;

            Logger.Information("Running {0}", name);

            if (part.TryCatch) {
                try {
                    _tfl.Run(new TransformalizeRequest(part, new Dictionary<string, string>(), null, Logger));
                } catch (Exception ex) {
                    Logger.Error(ex, ex.Message);
                }
            } else {
                _tfl.Run(new TransformalizeRequest(part, new Dictionary<string, string>(), null, Logger));
            }
        }
コード例 #24
0
        public void Sweep() {
            var taskEntries = _repository.Fetch(x => x.ScheduledUtc <= _clock.UtcNow)
                .Select(x => new { x.Id, Action = x.TaskType })
                .ToArray();

            foreach (var taskEntry in taskEntries) {
                //TODO: start a dedicated transaction scope

                try {
                    // fetch the task
                    var taskRecord = _repository.Get(taskEntry.Id);

                    // another server or thread has performed this work before us
                    if (taskRecord == null) {
                        continue;
                    }

                    // removing record first helps avoid concurrent execution
                    _repository.Delete(taskRecord);

                    var context = new ScheduledTaskContext {
                        Task = new Task(_contentManager, taskRecord)
                    };

                    // dispatch to standard or custom handlers
                    foreach (var handler in _handlers) {
                        handler.Process(context);
                    }

                    //TODO: commit dedicated scope
                }
                catch (Exception ex) {
                    Logger.Warning(ex, "Unable to process scheduled task #{0} of type {1}", taskEntry.Id, taskEntry.Action);

                    //TODO: handle exception to rollback dedicated xact, and re-delete task record. 
                    // does this also need some retry logic?
                }
            }
        }
コード例 #25
0
        public void Process(ScheduledTaskContext context) {
            if (context.Task.TaskType == Constants.FeaturedProductWinnersTask) {
                Logger.Information("Handling daily featured products at {0}",
                    context.Task.ScheduledUtc);

                // Handle the task
                _featuredProductService.HandleFeaturedProductWinners();
                
                // Get all current featured products
                var featured = _featuredProductService
                    .GetFeaturedProductsByDate(DateTime.UtcNow.AddDays(1))
                    .List();

                // Disable the bids for the featured products
                foreach (var ft in featured) {
                    ft.As<BidsPart>().BidsActive = false;
                }

                // Schedule next
                NextTaskDate();
            }
        }
コード例 #26
0
          public void Process(ScheduledTaskContext context)
          {
             if (context.Task.TaskType == TaskType)
             {
               try
               {
                   _threadLastReadService.PurgeLastReadRepository();
               }
               catch (Exception e)
               {
                 this.Logger.Error(e, e.Message);
               }
               finally
               {
                    //re-run the purge every day);
                    DateTime nextTaskDate = DateTime.UtcNow.AddDays(1);
                    //for testing
                    //DateTime nextTaskDate = DateTime.UtcNow.AddMinutes(1);
                    this.ScheduleNextTask(nextTaskDate);

               }         
             }
          }
コード例 #27
0
 public void Process(ScheduledTaskContext context) {
     TaskContext = context;
 }