Beispiel #1
0
        private void StartNewTasks()
        {
            List <TaskQueue> tasksNotStarted = TaskQueue.GetTasksNotStarted();

            foreach (TaskQueue task in tasksNotStarted)
            {
                if ((task.SerializedTaskType.Length == 0) || (task.SerializedTaskObject.Length == 0))
                {
                    // is a task somehow gets queued without a task type or serialized object
                    // just set it as completed
                    task.CompleteRatio = 1;
                    task.CompleteUTC   = DateTime.UtcNow;
                    task.Save();
                    continue;
                }

                Type t = null;

                try
                {
                    t = Type.GetType(task.SerializedTaskType);
                }
                catch (ArgumentException) { }
                catch (TypeLoadException) { }


                if (t == null)
                {
                    log.Error("Failed to deserialize and resume task " + task.TaskName);
                    task.CompleteRatio = 1;
                    task.CompleteUTC   = DateTime.UtcNow;
                    task.Save();
                    continue;
                }

                try
                {
                    ITaskQueueTask qTask
                        = (ITaskQueueTask)SerializationHelper.DeserializeFromString(Type.GetType(task.SerializedTaskType), task.SerializedTaskObject);
                    if (qTask != null)
                    {
                        qTask.StartTask();
                    }
                    else
                    {
                        log.Error("Failed to deserialize and start task " + task.TaskName);
                    }
                }
                catch (InvalidOperationException ex)
                {
                    log.Error("Failed to deserialize and start task " + task.TaskName + " so cancelling task", ex);
                    task.CompleteRatio = 1;
                    task.CompleteUTC   = DateTime.UtcNow;
                    task.Save();
                    log.Info("Failed Serialized Task was: " + task.SerializedTaskObject);
                }
            }
        }
Beispiel #2
0
        private void ResumeOrKillStalledTasks()
        {
            List <TaskQueue> unfinshedTasks = TaskQueue.GetUnfinished();

            foreach (TaskQueue task in unfinshedTasks)
            {
                if (TaskQueue.IsStalled(task))
                {
                    if (task.CanResume)
                    {
                        Type t = Type.GetType(task.SerializedTaskType);

                        if (t == null)
                        {
                            log.Error("Failed to deserialize and resume task " + task.TaskName);
                            task.Status      = "Stalled";
                            task.CompleteUTC = DateTime.UtcNow;
                            task.Save();
                        }
                        else
                        {
                            try
                            {
                                ITaskQueueTask qTask
                                    = (ITaskQueueTask)SerializationHelper.DeserializeFromString(t, task.SerializedTaskObject);
                                if (qTask != null)
                                {
                                    qTask.ResumeTask();
                                }
                                else
                                {
                                    log.Error("Failed to deserialize and resume task " + task.TaskName);
                                }
                            }
                            catch (InvalidOperationException ex)
                            {
                                log.Error("Failed to deserialize and resume task " + task.TaskName + " so cancelling", ex);
                                task.CompleteRatio = 1;
                                task.CompleteUTC   = DateTime.UtcNow;
                                task.Save();
                                log.Info("Failed Serialized Task was: " + task.SerializedTaskObject);
                            }
                        }
                    }
                    else
                    {
                        // TODO: localize
                        task.Status      = "Stalled";
                        task.CompleteUTC = DateTime.UtcNow;
                        task.Save();
                    }
                }
            }
        }