예제 #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 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");
        }
예제 #2
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();
        }
예제 #3
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();
        }
예제 #4
0
 private void GetParams(HttpContext context)
 {
     taskGuid = WebUtils.ParseGuidFromQueryString("t", taskGuid);
     task = new TaskQueue(taskGuid);
     if (task.Guid == Guid.Empty) { task = null; }
 }
예제 #5
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);
        }
예제 #6
0
 /// <summary>
 /// Compares 2 instances of TaskQueue.
 /// </summary>
 public static int CompareBySerializedTaskType(TaskQueue taskQueue1, TaskQueue taskQueue2)
 {
     return(taskQueue1.SerializedTaskType.CompareTo(taskQueue2.SerializedTaskType));
 }
예제 #7
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();
        }
예제 #8
0
 /// <summary>
 /// Compares 2 instances of TaskQueue.
 /// </summary>
 public static int CompareByTaskName(TaskQueue taskQueue1, TaskQueue taskQueue2)
 {
     return taskQueue1.TaskName.CompareTo(taskQueue2.TaskName);
 }
예제 #9
0
        public static bool IsStalled(TaskQueue task)
        {
            // TODO: make config setting
            int taskTimeoutPaddingSeconds = 300; //5 minutes

            return (DateTime.UtcNow > task.LastStatusUpdateUTC.AddSeconds(task.UpdateFrequency + taskTimeoutPaddingSeconds));
        }
예제 #10
0
 /// <summary>
 /// Compares 2 instances of TaskQueue.
 /// </summary>
 public static int CompareByStartUTC(TaskQueue taskQueue1, TaskQueue taskQueue2)
 {
     return taskQueue1.StartUTC.CompareTo(taskQueue2.StartUTC);
 }
예제 #11
0
 /// <summary>
 /// Compares 2 instances of TaskQueue.
 /// </summary>
 public static int CompareByStatus(TaskQueue taskQueue1, TaskQueue taskQueue2)
 {
     return taskQueue1.Status.CompareTo(taskQueue2.Status);
 }
예제 #12
0
 /// <summary>
 /// Compares 2 instances of TaskQueue.
 /// </summary>
 public static int CompareBySerializedTaskType(TaskQueue taskQueue1, TaskQueue taskQueue2)
 {
     return taskQueue1.SerializedTaskType.CompareTo(taskQueue2.SerializedTaskType);
 }
예제 #13
0
 /// <summary>
 /// Compares 2 instances of TaskQueue.
 /// </summary>
 public static int CompareBySerializedTaskObject(TaskQueue taskQueue1, TaskQueue taskQueue2)
 {
     return taskQueue1.SerializedTaskObject.CompareTo(taskQueue2.SerializedTaskObject);
 }
예제 #14
0
 /// <summary>
 /// Compares 2 instances of TaskQueue.
 /// </summary>
 public static int CompareByQueuedUTC(TaskQueue taskQueue1, TaskQueue taskQueue2)
 {
     return taskQueue1.QueuedUTC.CompareTo(taskQueue2.QueuedUTC);
 }
예제 #15
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();
 }
예제 #16
0
        private static List<TaskQueue> LoadListFromReader(IDataReader reader)
        {
            List<TaskQueue> taskQueueList = new List<TaskQueue>();
            try
            {
                while (reader.Read())
                {
                    TaskQueue taskQueue = new TaskQueue();
                    taskQueue.guid = new Guid(reader["Guid"].ToString());
                    taskQueue.siteGuid = new Guid(reader["SiteGuid"].ToString());
                    taskQueue.queuedBy = new Guid(reader["QueuedBy"].ToString());
                    taskQueue.taskName = reader["TaskName"].ToString();
                    taskQueue.notifyOnCompletion = Convert.ToBoolean(reader["NotifyOnCompletion"]);
                    taskQueue.notificationToEmail = reader["NotificationToEmail"].ToString();
                    taskQueue.notificationFromEmail = reader["NotificationFromEmail"].ToString();
                    taskQueue.notificationSubject = reader["NotificationSubject"].ToString();
                    taskQueue.taskCompleteMessage = reader["TaskCompleteMessage"].ToString();

                    if (reader["NotificationSentUTC"] != DBNull.Value)
                        taskQueue.notificationSentUTC = Convert.ToDateTime(reader["NotificationSentUTC"]);

                    taskQueue.canStop = Convert.ToBoolean(reader["CanStop"]);
                    taskQueue.canResume = Convert.ToBoolean(reader["CanResume"]);
                    taskQueue.updateFrequency = Convert.ToInt32(reader["UpdateFrequency"]);
                    taskQueue.queuedUTC = Convert.ToDateTime(reader["QueuedUTC"]);

                    if (reader["StartUTC"] != DBNull.Value)
                        taskQueue.startUTC = Convert.ToDateTime(reader["StartUTC"]);

                    if (reader["CompleteUTC"] != DBNull.Value)
                        taskQueue.completeUTC = Convert.ToDateTime(reader["CompleteUTC"]);

                    if (reader["LastStatusUpdateUTC"] != DBNull.Value)
                        taskQueue.lastStatusUpdateUTC = Convert.ToDateTime(reader["LastStatusUpdateUTC"]);

                    taskQueue.completeRatio = Convert.ToDouble(reader["CompleteRatio"]);
                    taskQueue.status = reader["Status"].ToString();
                    taskQueue.serializedTaskObject = reader["SerializedTaskObject"].ToString();
                    taskQueue.serializedTaskType = reader["SerializedTaskType"].ToString();

                    taskQueueList.Add(taskQueue);

                }
            }
            finally
            {
                reader.Close();
            }

            return taskQueueList;
        }
예제 #17
0
 /// <summary>
 /// Compares 2 instances of TaskQueue.
 /// </summary>
 public static int CompareByLastStatusUpdateUTC(TaskQueue taskQueue1, TaskQueue taskQueue2)
 {
     return taskQueue1.LastStatusUpdateUTC.CompareTo(taskQueue2.LastStatusUpdateUTC);
 }
예제 #18
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);
        }
예제 #19
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));
        }
예제 #20
0
 /// <summary>
 /// Compares 2 instances of TaskQueue.
 /// </summary>
 public static int CompareByTaskName(TaskQueue taskQueue1, TaskQueue taskQueue2)
 {
     return(taskQueue1.TaskName.CompareTo(taskQueue2.TaskName));
 }
예제 #21
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();
        }
예제 #22
0
 /// <summary>
 /// Compares 2 instances of TaskQueue.
 /// </summary>
 public static int CompareByQueuedUTC(TaskQueue taskQueue1, TaskQueue taskQueue2)
 {
     return(taskQueue1.QueuedUTC.CompareTo(taskQueue2.QueuedUTC));
 }
예제 #23
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);
        }
예제 #24
0
 /// <summary>
 /// Compares 2 instances of TaskQueue.
 /// </summary>
 public static int CompareByStartUTC(TaskQueue taskQueue1, TaskQueue taskQueue2)
 {
     return(taskQueue1.StartUTC.CompareTo(taskQueue2.StartUTC));
 }
예제 #25
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();
        }
예제 #26
0
 /// <summary>
 /// Compares 2 instances of TaskQueue.
 /// </summary>
 public static int CompareByCompleteUTC(TaskQueue taskQueue1, TaskQueue taskQueue2)
 {
     return(taskQueue1.CompleteUTC.CompareTo(taskQueue2.CompleteUTC));
 }
예제 #27
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();
        }
예제 #28
0
 /// <summary>
 /// Compares 2 instances of TaskQueue.
 /// </summary>
 public static int CompareByLastStatusUpdateUTC(TaskQueue taskQueue1, TaskQueue taskQueue2)
 {
     return(taskQueue1.LastStatusUpdateUTC.CompareTo(taskQueue2.LastStatusUpdateUTC));
 }
예제 #29
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();
        }
예제 #30
0
 /// <summary>
 /// Compares 2 instances of TaskQueue.
 /// </summary>
 public static int CompareByStatus(TaskQueue taskQueue1, TaskQueue taskQueue2)
 {
     return(taskQueue1.Status.CompareTo(taskQueue2.Status));
 }
예제 #31
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);

            }
        }
예제 #32
0
 /// <summary>
 /// Compares 2 instances of TaskQueue.
 /// </summary>
 public static int CompareBySerializedTaskObject(TaskQueue taskQueue1, TaskQueue taskQueue2)
 {
     return(taskQueue1.SerializedTaskObject.CompareTo(taskQueue2.SerializedTaskObject));
 }
예제 #33
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();
        }
예제 #34
0
 /// <summary>
 /// Compares 2 instances of TaskQueue.
 /// </summary>
 public static int CompareByCompleteUTC(TaskQueue taskQueue1, TaskQueue taskQueue2)
 {
     return taskQueue1.CompleteUTC.CompareTo(taskQueue2.CompleteUTC);
 }