Ejemplo n.º 1
0
        public void StartTask()
        {
            if (this.taskGuid == Guid.Empty)
            {
                return;
            }

            TaskQueue task = new TaskQueue(this.taskGuid);

            if (task.Guid == Guid.Empty)
            {
                return;                          // task not found
            }
            if (!ThreadPool.QueueUserWorkItem(new WaitCallback(RunTaskOnNewThread), this))
            {
                throw new Exception("Couldn't queue the task on a new thread.");
            }

            task.Status              = "Started";
            task.StartUTC            = DateTime.UtcNow;
            task.LastStatusUpdateUTC = DateTime.UtcNow;
            task.Save();

            log.Info("Queued ThreadSleepTask on a new thread");
        }
Ejemplo n.º 2
0
        public void QueueTask()
        {
            if (this.siteGuid == Guid.Empty)
            {
                return;
            }

            if (this.taskGuid != Guid.Empty)
            {
                return;
            }


            TaskQueue task = new TaskQueue();

            task.SiteGuid              = this.siteGuid;
            task.QueuedBy              = this.queuedBy;
            task.TaskName              = this.taskName;
            task.NotifyOnCompletion    = this.notifyOnCompletion;
            task.NotificationToEmail   = this.notificationToEmail;
            task.NotificationFromEmail = this.notificationFromEmail;
            task.NotificationSubject   = this.notificationSubject;
            task.TaskCompleteMessage   = this.taskCompleteMessage;
            task.CanResume             = this.canResume;
            task.CanStop              = this.canStop;
            task.UpdateFrequency      = this.updateFrequency;
            task.Status               = "Queued";
            task.LastStatusUpdateUTC  = DateTime.UtcNow;
            this.taskGuid             = task.NewGuid;
            task.SerializedTaskObject = SerializationHelper.SerializeToString(this);
            task.SerializedTaskType   = this.GetType().AssemblyQualifiedName;
            task.Save();
        }
Ejemplo n.º 3
0
        private void ReportStatus()
        {
            TaskQueue task = new TaskQueue(this.taskGuid);

            if (totalSubscribersToSend > 0)
            {
                task.CompleteRatio = (subscribersSentSoFar / totalSubscribersToSend);
            }
            else
            {
                task.CompleteRatio = 1; //nothing to send so mark as complete
            }

            if (task.CompleteRatio >= 1)
            {
                task.Status = statusCompleteMessage;

                if (task.CompleteUTC == DateTime.MinValue)
                {
                    task.CompleteUTC = DateTime.UtcNow;
                }

                Letter letter = new Letter(this.letterGuid);
                letter.TrackSendComplete(LetterSendLog.GetCount(letter.LetterGuid));
            }
            else
            {
                task.Status = string.Format(
                    CultureInfo.InvariantCulture,
                    statusRunningMessage,
                    subscribersSentSoFar,
                    totalSubscribersToSend);
            }


            task.LastStatusUpdateUTC = DateTime.UtcNow;
            task.Save();

            nextStatusUpdateTime = DateTime.UtcNow.AddSeconds(updateFrequency);
        }
Ejemplo n.º 4
0
        private void RunTask()
        {
            startTime = DateTime.UtcNow;
            endTime   = startTime.AddMinutes(maxRunTimeMinutes);
            timeToRun = endTime.Subtract(startTime);


            while (DateTime.UtcNow < endTime)
            {
                countOfIterations += 1;
                DoReporting();
                DoSleeping();
            }

            TaskQueue task = new TaskQueue(this.taskGuid);

            task.Status              = "Finished";
            task.CompleteRatio       = 1;
            task.LastStatusUpdateUTC = DateTime.UtcNow;
            task.CompleteUTC         = DateTime.UtcNow;
            task.Save();
        }
Ejemplo n.º 5
0
        private void DoReporting()
        {
            if (this.taskGuid == Guid.Empty)
            {
                return;
            }



            TaskQueue task = new TaskQueue(this.taskGuid);

            task.Status = "Running " + countOfIterations.ToString(CultureInfo.InvariantCulture);
            if ((timeToRun != null) && (timeToRun.TotalSeconds > 0))
            {
                TimeSpan timeLeft = endTime.Subtract(DateTime.UtcNow);
                task.CompleteRatio = ((timeToRun.TotalSeconds - timeLeft.TotalSeconds) / timeToRun.TotalSeconds);
            }
            task.LastStatusUpdateUTC = DateTime.UtcNow;
            task.Save();

            log.Info("Task " + task.TaskName
                     + " completed iteration "
                     + countOfIterations.ToString(CultureInfo.InvariantCulture));
        }
Ejemplo n.º 6
0
        public void QueueTask()
        {
            //if (this.siteGuid == Guid.Empty) return;

            if (this.taskGuid != Guid.Empty) return;

            if (this.urlToRequest.Length == 0) return;

            TaskQueue task = new TaskQueue();
            task.SiteGuid = this.siteGuid;
            task.TaskName = this.taskName;
            task.Status = "Queued";
            task.LastStatusUpdateUTC = DateTime.UtcNow;
            this.taskGuid = task.NewGuid;
            task.SerializedTaskObject = SerializationHelper.SerializeToString(this);
            task.SerializedTaskType = this.GetType().AssemblyQualifiedName;
            task.Save();
        }
Ejemplo n.º 7
0
        private void ReportStatus()
        {
            TaskQueue task = new TaskQueue(this.taskGuid);

            task.CompleteRatio = 1; //nothing to do so mark as complete
            task.Status = statusCompleteMessage;

            if (task.CompleteUTC == DateTime.MinValue)
                task.CompleteUTC = DateTime.UtcNow;

            task.LastStatusUpdateUTC = DateTime.UtcNow;
            task.Save();
        }
Ejemplo n.º 8
0
        public void QueueTask()
        {
            if (this.siteGuid == Guid.Empty) return;

            // don't queue a task that has already been created
            if (this.taskGuid != Guid.Empty) return;

            TaskQueue task = new TaskQueue();
            task.SiteGuid = this.siteGuid;
            task.QueuedBy = this.queuedBy;
            task.TaskName = this.taskName;
            task.NotifyOnCompletion = this.notifyOnCompletion;
            task.NotificationToEmail = this.notificationToEmail;
            task.NotificationFromEmail = this.notificationFromEmail;
            task.NotificationSubject = this.notificationSubject;
            task.TaskCompleteMessage = this.taskCompleteMessage;
            task.CanResume = this.canResume;
            task.CanStop = this.canStop;
            task.UpdateFrequency = this.updateFrequency;
            task.Status = statusQueuedMessage;
            task.LastStatusUpdateUTC = DateTime.UtcNow;
            this.taskGuid = task.NewGuid;
            task.SerializedTaskObject = SerializationHelper.SerializeToString(this);
            task.SerializedTaskType = this.GetType().AssemblyQualifiedName;
            task.Save();
        }
Ejemplo n.º 9
0
        private void RunTask()
        {
            unfinshedTasks = TaskQueue.GetUnfinished();
            tasksNotStarted = TaskQueue.GetTasksNotStarted();

            while ((unfinshedTasks.Count > 0) || (tasksNotStarted.Count > 0))
            {
                ResumeOrKillStalledTasks();
                StartNewTasks();
                DoReporting();
                DoSleeping();
                unfinshedTasks = TaskQueue.GetUnfinished();
                tasksNotStarted = TaskQueue.GetTasksNotStarted();

                if ((tasksNotStarted.Count == 0) && (unfinshedTasks.Count == 1))
                {
                    if(unfinshedTasks[0].SerializedTaskType == this.GetType().AssemblyQualifiedName)
                    break;
                }

            }

            TaskQueue task = new TaskQueue(this.taskGuid);
            task.Status = statusCompleteMessage;
            task.CompleteRatio = 1;
            task.LastStatusUpdateUTC = DateTime.UtcNow;
            task.CompleteUTC = DateTime.UtcNow;
            task.Save();
        }
Ejemplo n.º 10
0
        private void DoReporting()
        {
            if (this.taskGuid == Guid.Empty) return;

            TaskQueue task = new TaskQueue(this.taskGuid);
            task.Status = statusRunningMessage;
            task.CompleteRatio = 0.5;
            task.LastStatusUpdateUTC = DateTime.UtcNow;
            task.Save();
        }
Ejemplo n.º 11
0
        private void DoReporting()
        {
            if (this.taskGuid == Guid.Empty) return;

            TaskQueue task = new TaskQueue(this.taskGuid);
            task.Status = "Running " + countOfIterations.ToString(CultureInfo.InvariantCulture);
            if ((timeToRun != null)&&(timeToRun.TotalSeconds > 0))
            {
                TimeSpan timeLeft = endTime.Subtract(DateTime.UtcNow);
                task.CompleteRatio = ((timeToRun.TotalSeconds - timeLeft.TotalSeconds)/timeToRun.TotalSeconds);

            }
            task.LastStatusUpdateUTC = DateTime.UtcNow;
            task.Save();

            log.Info("Task " + task.TaskName
                + " completed iteration "
                + countOfIterations.ToString(CultureInfo.InvariantCulture));
        }
Ejemplo n.º 12
0
 private void MarkAsComplete()
 {
     TaskQueue task = new TaskQueue(this.taskGuid);
     task.Status = statusCompleteMessage;
     task.CompleteRatio = 1;
     task.LastStatusUpdateUTC = DateTime.UtcNow;
     task.CompleteUTC = DateTime.UtcNow;
     task.Save();
 }
Ejemplo n.º 13
0
        private void ReportStatus()
        {
            TaskQueue task = new TaskQueue(this.taskGuid);

            if (totalSubscribersToSend > 0)
            {

                task.CompleteRatio = (subscribersSentSoFar / totalSubscribersToSend);
            }
            else
            {
                task.CompleteRatio = 1; //nothing to send so mark as complete
            }

            if (task.CompleteRatio >= 1)
            {
                task.Status = statusCompleteMessage;

                if(task.CompleteUTC == DateTime.MinValue)
                task.CompleteUTC = DateTime.UtcNow;

                Letter letter = new Letter(this.letterGuid);
                letter.TrackSendComplete(LetterSendLog.GetCount(letter.LetterGuid));

            }
            else
            {
                task.Status = string.Format(
                    CultureInfo.InvariantCulture,
                    statusRunningMessage,
                    subscribersSentSoFar,
                    totalSubscribersToSend);
            }

            task.LastStatusUpdateUTC = DateTime.UtcNow;
            task.Save();

            nextStatusUpdateTime = DateTime.UtcNow.AddSeconds(updateFrequency);
        }
Ejemplo n.º 14
0
        private void ReportSleeping()
        {
            TaskQueue task = new TaskQueue(this.taskGuid);

            try
            {
                task.Status = string.Format(
                    CultureInfo.InvariantCulture,
                    Resource.NewsletterSleepingFormat,
                    subscribersSentSoFar,
                    totalSubscribersToSend);
            }
            catch (FormatException)
            {
                task.Status = "sleeping to throttle send rate";
            }

            task.LastStatusUpdateUTC = DateTime.UtcNow;
            task.Save();
        }
Ejemplo n.º 15
0
        private void RunTask()
        {
            startTime = DateTime.UtcNow;
            endTime = startTime.AddMinutes(maxRunTimeMinutes);
            timeToRun = endTime.Subtract(startTime);

            while (DateTime.UtcNow < endTime)
            {
                countOfIterations += 1;
                DoReporting();
                DoSleeping();
            }

            TaskQueue task = new TaskQueue(this.taskGuid);
            task.Status = "Finished";
            task.CompleteRatio = 1;
            task.LastStatusUpdateUTC = DateTime.UtcNow;
            task.CompleteUTC = DateTime.UtcNow;
            task.Save();
        }
Ejemplo n.º 16
0
        public void StartTask()
        {
            if (this.taskGuid == Guid.Empty) return;

            TaskQueue task = new TaskQueue(this.taskGuid);

            if (task.Guid == Guid.Empty) return; // task not found

            if (!ThreadPool.QueueUserWorkItem(new WaitCallback(RunTaskOnNewThread), this))
            {
                throw new Exception("Couldn't queue the AppKeepAliveTask task on a new thread.");
            }

            task.Status = "Started";
            task.StartUTC = DateTime.UtcNow;
            task.LastStatusUpdateUTC = DateTime.UtcNow;
            task.Save();

            log.Info("Queued AppKeepAliveTask on a new thread");
        }
Ejemplo n.º 17
0
        private void DoKeepAlive()
        {
            if (this.taskGuid == Guid.Empty) return;

            TaskQueue task = new TaskQueue(this.taskGuid);
            task.Status = "Running";

            task.LastStatusUpdateUTC = DateTime.UtcNow;
            task.Save();

            if (urlToRequest.Length == 0)
            {
                log.Info("No url provided for app keep alive task so task is quiting");
                //make the task end
                endTime = DateTime.UtcNow;
                return;
            }

            //make web request to keep the app alive
            try
            {
                HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(urlToRequest);
                webRequest.Method = "GET";
                HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse();
            }
            catch (UriFormatException ex)
            {
                webErrorCount = maxAllowedWebErrors; // this particular error means the ulr is bad so no need to try again
                log.Error(ex);

            }
            catch (NotSupportedException ex)
            {
                webErrorCount = maxAllowedWebErrors; // no need to try again
                log.Error(ex);

            }
            catch (System.Security.SecurityException ex)
            {
                webErrorCount = maxAllowedWebErrors; // no need to try again
                log.Error(ex);

            }
            catch (WebException ex)
            {
                webErrorCount += 1;
                log.Error(ex);

            }
            catch (InvalidOperationException ex)
            {
                webErrorCount = maxAllowedWebErrors; // no need to try again
                log.Error(ex);

            }
        }
Ejemplo n.º 18
0
        private void ReportStatus(double completeRatio)
        {
            TaskQueue task = new TaskQueue(this.taskGuid);
               task.CompleteRatio = completeRatio;

               if (task.CompleteRatio >= 1)
               {
               task.Status = statusCompleteMessage;

               if (task.CompleteUTC == DateTime.MinValue)
               {
                   task.CompleteUTC = DateTime.UtcNow;
               }

               }
               else
               {
               task.Status = this.statusRunningMessage;
               }

               task.LastStatusUpdateUTC = DateTime.UtcNow;
               task.Save();

               //nextStatusUpdateTime = DateTime.UtcNow.AddSeconds(updateFrequency);
        }
Ejemplo n.º 19
0
        private void RunTask()
        {
            if (IsAlreadyRunning())
            {
                MarkAsComplete();
                return;
            }

            startTime = DateTime.UtcNow;
            endTime = startTime.AddMinutes(maxRunTimeMinutes);
            timeToRun = endTime.Subtract(startTime);

            while ((DateTime.UtcNow < endTime)&&(webErrorCount < maxAllowedWebErrors))
            {
                countOfIterations += 1;
                DoKeepAlive();
                DoSleeping();
            }

            TaskQueue task = new TaskQueue(this.taskGuid);
            task.Status = "Finished";
            task.CompleteRatio = 1;
            task.LastStatusUpdateUTC = DateTime.UtcNow;
            task.CompleteUTC = DateTime.UtcNow;
            task.Save();
        }
Ejemplo n.º 20
0
        private void ReportStatus(bool markAsComplete)
        {
            TaskQueue task = new TaskQueue(this.taskGuid);

            if (markAsComplete)
            {
                if (rowsToProcess > 0)
                {

                    task.CompleteRatio = (rowsProcessed / rowsToProcess);
                }
                else
                {
                    task.CompleteRatio = 1; //nothing to do so mark as complete
                }
            }

            if (task.CompleteRatio >= 1)
            {
                task.Status = statusCompleteMessage;

                if (task.CompleteUTC == DateTime.MinValue)
                    task.CompleteUTC = DateTime.UtcNow;

            }
            else
            {
                task.Status = string.Format(
                    CultureInfo.InvariantCulture,
                    statusRunningMessage,
                    rowsProcessed,
                    rowsToProcess);
            }

            task.LastStatusUpdateUTC = DateTime.UtcNow;
            task.Save();

            nextStatusUpdateTime = DateTime.UtcNow.AddSeconds(actualUpdateFrequency);
        }