fixed bugs Scheduler Service

This commit is contained in:
vfedosevich 2013-05-24 15:46:10 +03:00
parent d14b5fc01f
commit 20f4b371d1
30 changed files with 332 additions and 190 deletions

View file

@ -40,7 +40,7 @@ namespace WebsitePanel.EnterpriseServer.Tasks
public override void OnComplete()
{
BackgroundTask topTask = TaskController.GetTopTask();
BackgroundTask topTask = TaskManager.TopTask;
if (!TaskManager.HasErrors(topTask))
{
@ -78,7 +78,7 @@ namespace WebsitePanel.EnterpriseServer.Tasks
{
try
{
BackgroundTask topTask = TaskController.GetTopTask();
BackgroundTask topTask = TaskManager.TopTask;
bool sendLetter = Utils.ParseBool(topTask.GetParamValue("SendLetter"), false);
@ -98,7 +98,7 @@ namespace WebsitePanel.EnterpriseServer.Tasks
{
try
{
BackgroundTask topTask = TaskController.GetTopTask();
BackgroundTask topTask = TaskManager.TopTask;
int userId = Utils.ParseInt(topTask.GetParamValue("UserId").ToString(), 0);
bool sendLetter = Utils.ParseBool(topTask.GetParamValue("SendLetter"), false);
@ -125,7 +125,7 @@ namespace WebsitePanel.EnterpriseServer.Tasks
{
try
{
BackgroundTask topTask = TaskController.GetTopTask();
BackgroundTask topTask = TaskManager.TopTask;
bool sendLetter = Utils.ParseBool(topTask.GetParamValue("SendLetter"), false);

View file

@ -15,32 +15,39 @@ namespace WebsitePanel.EnterpriseServer
BackgroundTask task = ObjectUtils.FillObjectFromDataReader<BackgroundTask>(
DataProvider.GetBackgroundTask(SecurityContext.User.UserId, taskId));
if (task == null)
{
return null;
}
task.Params = GetTaskParams(task.Id);
return task;
}
public static List<BackgroundTask> GetScheduleTasks(int scheduleId)
{
return ObjectUtils.CreateListFromDataReader<BackgroundTask>(
DataProvider.GetScheduleBackgroundTasks(SecurityContext.User.UserId, scheduleId));
}
public static List<BackgroundTask> GetTasks()
{
return ObjectUtils.CreateListFromDataReader<BackgroundTask>(
DataProvider.GetBackgroundTasks(SecurityContext.User.UserId));
}
public static List<BackgroundTask> GetTasks(Guid guid)
{
return ObjectUtils.CreateListFromDataReader<BackgroundTask>(
DataProvider.GetBackgroundTasks(SecurityContext.User.UserId, guid));
}
public static List<BackgroundTask> GetProcessTasks(BackgroundTaskStatus status)
{
return ObjectUtils.CreateListFromDataReader<BackgroundTask>(
DataProvider.GetProcessBackgroundTasks(SecurityContext.User.UserId, status));
}
public static BackgroundTask GetTopTask()
public static BackgroundTask GetTopTask(Guid guid)
{
BackgroundTask task = ObjectUtils.FillObjectFromDataReader<BackgroundTask>(
DataProvider.GetBackgroundTopTask(SecurityContext.User.UserId));
DataProvider.GetBackgroundTopTask(SecurityContext.User.UserId, guid));
task.Params = GetTaskParams(task.Id);
@ -49,7 +56,7 @@ namespace WebsitePanel.EnterpriseServer
public static void AddTask(BackgroundTask task)
{
int taskId = DataProvider.AddBackgroundTask(task.TaskId, task.ScheduleId, task.PackageId, task.UserId,
int taskId = DataProvider.AddBackgroundTask(task.Guid, task.TaskId, task.ScheduleId, task.PackageId, task.UserId,
task.EffectiveUserId, task.TaskName, task.ItemId, task.ItemName,
task.StartDate, task.IndicatorCurrent, task.IndicatorMaximum,
task.MaximumExecutionTime, task.Source, task.Severity, task.Completed,
@ -62,14 +69,14 @@ namespace WebsitePanel.EnterpriseServer
public static void UpdateTask(BackgroundTask task)
{
DataProvider.UpdateBackgroundTask(task.Id, task.ScheduleId, task.PackageId, task.TaskName, task.ItemId,
DataProvider.UpdateBackgroundTask(task.Guid, task.Id, task.ScheduleId, task.PackageId, task.TaskName, task.ItemId,
task.ItemName, task.FinishDate, task.IndicatorCurrent,
task.IndicatorMaximum, task.MaximumExecutionTime, task.Source,
task.Severity, task.Completed, task.NotifyOnComplete, task.Status);
AddTaskParams(task.Id, task.Params);
if (task.Completed || task.Status == BackgroundTaskStatus.Abort)
if (task.Completed || task.Status == BackgroundTaskStatus.Abort || task.Status == BackgroundTaskStatus.Stopping)
{
DeleteTaskStack(task.Id);
}
@ -82,6 +89,11 @@ namespace WebsitePanel.EnterpriseServer
public static void AddTaskParams(int taskId, List<BackgroundTaskParameter> parameters)
{
if (parameters == null)
{
return;
}
foreach (BackgroundTaskParameter param in SerializeParams(parameters))
{
DataProvider.AddBackgroundTaskParam(taskId, param.Name, param.SerializerValue);
@ -117,14 +129,11 @@ namespace WebsitePanel.EnterpriseServer
private static List<BackgroundTaskParameter> SerializeParams(List<BackgroundTaskParameter> parameters)
{
if (parameters == null)
{
return new List<BackgroundTaskParameter>();
}
foreach (BackgroundTaskParameter param in parameters)
{
XmlSerializer serializer = new XmlSerializer(param.Value.GetType());
param.TypeName = param.Value.GetType().Name;
XmlSerializer serializer = new XmlSerializer(Type.GetType(param.TypeName));
MemoryStream ms = new MemoryStream();
serializer.Serialize(ms, param.Value);
@ -141,7 +150,7 @@ namespace WebsitePanel.EnterpriseServer
{
foreach (BackgroundTaskParameter param in parameters)
{
XmlSerializer deserializer = new XmlSerializer(param.SerializerValue.GetType());
XmlSerializer deserializer = new XmlSerializer(Type.GetType(param.TypeName));
StringReader sr = new StringReader(param.SerializerValue);
param.Value = deserializer.Deserialize(sr);

View file

@ -52,6 +52,20 @@ namespace WebsitePanel.EnterpriseServer
60000, // start from 1 minute
60000); // invoke each minute
protected static Guid? _Guid;
public static Guid Guid
{
get
{
if (_Guid == null)
{
_Guid = Guid.NewGuid();
}
return _Guid.Value;
}
}
public static void StartTask(string source, string taskName)
{
@ -142,10 +156,10 @@ namespace WebsitePanel.EnterpriseServer
int effectiveUserId = SecurityContext.User.IsPeer ? SecurityContext.User.OwnerId : userId;
String itemNameStr = itemName != null ? itemName.ToString() : String.Empty;
BackgroundTask task = new BackgroundTask(taskId, userId, effectiveUserId, source, taskName, itemNameStr,
BackgroundTask task = new BackgroundTask(Guid, taskId, userId, effectiveUserId, source, taskName, itemNameStr,
itemId, scheduleId, packageId, maximumExecutionTime, parameters);
List<BackgroundTask> tasks = TaskController.GetTasks();
List<BackgroundTask> tasks = TaskController.GetTasks(Guid);
if (tasks.Count > 0)
{
@ -191,10 +205,10 @@ namespace WebsitePanel.EnterpriseServer
// ERROR
WriteLogRecord(2, ex.Message, ex.StackTrace);
BackgroundTask topTask = TaskController.GetTopTask();
return new Exception((topTask != null) ? String.Format("Error executing '{0}' task on '{1}' {2}",
topTask.TaskName, topTask.ItemName, topTask.Source) : String.Format("Error executing task"), ex);
return new Exception((TopTask != null)
? String.Format("Error executing '{0}' task on '{1}' {2}",
TopTask.TaskName, TopTask.ItemName, TopTask.Source)
: String.Format("Error executing task"), ex);
}
public static void WriteError(Exception ex, string text, params string[] textParameters)
@ -219,7 +233,7 @@ namespace WebsitePanel.EnterpriseServer
private static void WriteLogRecord(int severity, string text, string stackTrace, params string[] textParameters)
{
List<BackgroundTask> tasks = TaskController.GetTasks();
List<BackgroundTask> tasks = TaskController.GetTasks(Guid);
if (tasks.Count > 0)
{
@ -246,12 +260,12 @@ namespace WebsitePanel.EnterpriseServer
public static void CompleteTask()
{
List<BackgroundTask> tasks = TaskController.GetTasks();
List<BackgroundTask> tasks = TaskController.GetTasks(Guid);
if (tasks.Count == 0)
return;
BackgroundTask topTask = TaskController.GetTopTask();
BackgroundTask topTask = tasks[tasks.Count - 1];
// call event handler
CallTaskEventHandler(topTask, true);
@ -284,7 +298,7 @@ namespace WebsitePanel.EnterpriseServer
public static void UpdateParam(String name, Object value)
{
BackgroundTask topTask = TaskController.GetTopTask();
BackgroundTask topTask = TopTask;
if (topTask == null)
return;
@ -298,7 +312,7 @@ namespace WebsitePanel.EnterpriseServer
{
set
{
BackgroundTask topTask = TaskController.GetTopTask();
BackgroundTask topTask = TopTask;
if (topTask == null)
return;
@ -313,7 +327,7 @@ namespace WebsitePanel.EnterpriseServer
{
set
{
BackgroundTask topTask = TaskController.GetTopTask();
BackgroundTask topTask = TopTask;
if (topTask == null)
return;
@ -326,7 +340,7 @@ namespace WebsitePanel.EnterpriseServer
public static void UpdateParams(Hashtable parameters)
{
BackgroundTask topTask = TaskController.GetTopTask();
BackgroundTask topTask = TopTask;
if (topTask == null)
return;
@ -393,7 +407,7 @@ namespace WebsitePanel.EnterpriseServer
static void PurgeCompletedTasks(object obj)
{
List<BackgroundTask> tasks = TaskController.GetTasks();
List<BackgroundTask> tasks = TaskController.GetTasks(Guid);
foreach (BackgroundTask task in tasks)
{
@ -411,7 +425,13 @@ namespace WebsitePanel.EnterpriseServer
{
set
{
BackgroundTask topTask = TaskController.GetTopTask();
BackgroundTask topTask = TopTask;
if (topTask == null)
{
return;
}
topTask.IndicatorMaximum = value;
TaskController.UpdateTask(topTask);
@ -422,11 +442,17 @@ namespace WebsitePanel.EnterpriseServer
{
get
{
return TaskController.GetTopTask().IndicatorCurrent;
return TopTask.IndicatorCurrent;
}
set
{
BackgroundTask topTask = TaskController.GetTopTask();
BackgroundTask topTask = TopTask;
if (topTask == null)
{
return;
}
topTask.IndicatorCurrent = value;
TaskController.UpdateTask(topTask);
@ -437,11 +463,17 @@ namespace WebsitePanel.EnterpriseServer
{
get
{
return TaskController.GetTopTask().MaximumExecutionTime;
return TopTask.MaximumExecutionTime;
}
set
{
BackgroundTask topTask = TaskController.GetTopTask();
BackgroundTask topTask = TopTask;
if (topTask == null)
{
return;
}
topTask.MaximumExecutionTime = value;
TaskController.UpdateTask(topTask);
@ -453,6 +485,11 @@ namespace WebsitePanel.EnterpriseServer
return task.Severity == 2;
}
public static BackgroundTask TopTask
{
get { return TaskController.GetTopTask(Guid); }
}
public static BackgroundTask GetTask(string taskId)
{
BackgroundTask task = TaskController.GetTask(taskId);