Esempio 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(RunTaskOnNewTopic), this))
            {
                throw new Exception("Couldn't queue the task on a new topic.");
            }

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

            log.Info("Queued TopicSleepTask on a new topic");
        }
Esempio 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();
        }
Esempio n. 3
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();
        }
Esempio n. 4
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));
        }