Scheduler service fixes
This commit is contained in:
parent
2cf0890e14
commit
bcceb95f92
3 changed files with 62 additions and 41 deletions
|
@ -42,18 +42,12 @@ namespace WebsitePanel.EnterpriseServer
|
||||||
|
|
||||||
public sealed class Scheduler
|
public sealed class Scheduler
|
||||||
{
|
{
|
||||||
public static SchedulerJob nextSchedule = null;
|
public static SchedulerJob nextSchedule = null;
|
||||||
|
private static Timer timer = new Timer(ScheduleTasks, null, 30000, 30000);
|
||||||
|
|
||||||
public static void Start()
|
public static void Start()
|
||||||
{
|
{
|
||||||
var serviceController = new ServiceController("WebsitePanel Scheduler");
|
ScheduleTasks();
|
||||||
|
|
||||||
if (serviceController != null && serviceController.Status != ServiceControllerStatus.Running)
|
|
||||||
{
|
|
||||||
serviceController.WaitForStatus(ServiceControllerStatus.Running);
|
|
||||||
}
|
|
||||||
|
|
||||||
ScheduleTasks(null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool IsScheduleActive(int scheduleId)
|
public static bool IsScheduleActive(int scheduleId)
|
||||||
|
@ -82,21 +76,23 @@ namespace WebsitePanel.EnterpriseServer
|
||||||
TaskManager.StopTask(activeTask.TaskId);
|
TaskManager.StopTask(activeTask.TaskId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void ScheduleTasks()
|
||||||
|
{
|
||||||
|
ScheduleTasks(null);
|
||||||
|
}
|
||||||
|
|
||||||
public static void ScheduleTasks(object obj)
|
public static void ScheduleTasks(object obj)
|
||||||
{
|
{
|
||||||
RunManualTasks();
|
RunManualTasks();
|
||||||
nextSchedule = SchedulerController.GetNextSchedule();
|
nextSchedule = SchedulerController.GetNextSchedule();
|
||||||
|
|
||||||
if (nextSchedule != null)
|
if (nextSchedule != null)
|
||||||
{
|
{
|
||||||
if (nextSchedule.ScheduleInfo.NextRun <= DateTime.Now)
|
if (nextSchedule.ScheduleInfo.NextRun <= DateTime.Now)
|
||||||
{
|
{
|
||||||
RunNextSchedule(null);
|
RunNextSchedule(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Thread.Sleep(30000);
|
|
||||||
ScheduleTasks(null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void RunManualTasks()
|
private static void RunManualTasks()
|
||||||
|
@ -155,14 +151,14 @@ namespace WebsitePanel.EnterpriseServer
|
||||||
|
|
||||||
// call back for the timer function
|
// call back for the timer function
|
||||||
static void RunNextSchedule(object obj) // obj ignored
|
static void RunNextSchedule(object obj) // obj ignored
|
||||||
{
|
{
|
||||||
if (nextSchedule == null)
|
if (nextSchedule == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
RunSchedule(nextSchedule, true);
|
RunSchedule(nextSchedule, true);
|
||||||
|
|
||||||
// schedule next task
|
// schedule next task
|
||||||
ScheduleTasks(null);
|
ScheduleTasks();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void RunSchedule(SchedulerJob schedule, bool changeNextRun)
|
static void RunSchedule(SchedulerJob schedule, bool changeNextRun)
|
||||||
|
|
|
@ -15,6 +15,11 @@ namespace WebsitePanel.EnterpriseServer
|
||||||
BackgroundTask task = ObjectUtils.FillObjectFromDataReader<BackgroundTask>(
|
BackgroundTask task = ObjectUtils.FillObjectFromDataReader<BackgroundTask>(
|
||||||
DataProvider.GetBackgroundTask(SecurityContext.User.UserId, taskId));
|
DataProvider.GetBackgroundTask(SecurityContext.User.UserId, taskId));
|
||||||
|
|
||||||
|
if (task == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
task.Params = GetTaskParams(task.Id);
|
task.Params = GetTaskParams(task.Id);
|
||||||
|
|
||||||
return task;
|
return task;
|
||||||
|
@ -27,9 +32,14 @@ namespace WebsitePanel.EnterpriseServer
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<BackgroundTask> GetTasks()
|
public static List<BackgroundTask> GetTasks()
|
||||||
|
{
|
||||||
|
return GetTasks(SecurityContext.User.UserId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<BackgroundTask> GetTasks(int actorId)
|
||||||
{
|
{
|
||||||
return ObjectUtils.CreateListFromDataReader<BackgroundTask>(
|
return ObjectUtils.CreateListFromDataReader<BackgroundTask>(
|
||||||
DataProvider.GetBackgroundTasks(SecurityContext.User.UserId));
|
DataProvider.GetBackgroundTasks(actorId));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<BackgroundTask> GetTasks(Guid guid)
|
public static List<BackgroundTask> GetTasks(Guid guid)
|
||||||
|
@ -49,6 +59,11 @@ namespace WebsitePanel.EnterpriseServer
|
||||||
BackgroundTask task = ObjectUtils.FillObjectFromDataReader<BackgroundTask>(
|
BackgroundTask task = ObjectUtils.FillObjectFromDataReader<BackgroundTask>(
|
||||||
DataProvider.GetBackgroundTopTask(SecurityContext.User.UserId, guid));
|
DataProvider.GetBackgroundTopTask(SecurityContext.User.UserId, guid));
|
||||||
|
|
||||||
|
if (task == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
task.Params = GetTaskParams(task.Id);
|
task.Params = GetTaskParams(task.Id);
|
||||||
|
|
||||||
return task;
|
return task;
|
||||||
|
@ -88,7 +103,7 @@ namespace WebsitePanel.EnterpriseServer
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void AddTaskParams(int taskId, List<BackgroundTaskParameter> parameters)
|
public static void AddTaskParams(int taskId, List<BackgroundTaskParameter> parameters)
|
||||||
{
|
{
|
||||||
foreach (BackgroundTaskParameter param in SerializeParams(parameters))
|
foreach (BackgroundTaskParameter param in SerializeParams(parameters))
|
||||||
{
|
{
|
||||||
DataProvider.AddBackgroundTaskParam(taskId, param.Name, param.SerializerValue, param.TypeName);
|
DataProvider.AddBackgroundTaskParam(taskId, param.Name, param.SerializerValue, param.TypeName);
|
||||||
|
@ -118,7 +133,7 @@ namespace WebsitePanel.EnterpriseServer
|
||||||
{
|
{
|
||||||
log.TextParameters = ReBuildParametersXml(log.XmlParameters);
|
log.TextParameters = ReBuildParametersXml(log.XmlParameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
return logs;
|
return logs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,7 +157,7 @@ namespace WebsitePanel.EnterpriseServer
|
||||||
return parameters;
|
return parameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<BackgroundTaskParameter> DeserializeParams(List<BackgroundTaskParameter> parameters)
|
private static List<BackgroundTaskParameter> DeserializeParams(List<BackgroundTaskParameter> parameters)
|
||||||
{
|
{
|
||||||
foreach (BackgroundTaskParameter param in parameters)
|
foreach (BackgroundTaskParameter param in parameters)
|
||||||
{
|
{
|
||||||
|
@ -188,3 +203,4 @@ namespace WebsitePanel.EnterpriseServer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -153,8 +153,13 @@ namespace WebsitePanel.EnterpriseServer
|
||||||
}
|
}
|
||||||
|
|
||||||
int userId = SecurityContext.User.OwnerId;
|
int userId = SecurityContext.User.OwnerId;
|
||||||
int effectiveUserId = SecurityContext.User.IsPeer ? SecurityContext.User.OwnerId : SecurityContext.User.UserId;
|
int effectiveUserId = SecurityContext.User.IsPeer
|
||||||
String itemNameStr = itemName != null ? itemName.ToString() : String.Empty;
|
? userId
|
||||||
|
: SecurityContext.User.UserId;
|
||||||
|
|
||||||
|
String itemNameStr = itemName != null
|
||||||
|
? itemName.ToString()
|
||||||
|
: String.Empty;
|
||||||
|
|
||||||
BackgroundTask task = new BackgroundTask(Guid, taskId, userId, effectiveUserId, source, taskName, itemNameStr,
|
BackgroundTask task = new BackgroundTask(Guid, taskId, userId, effectiveUserId, source, taskName, itemNameStr,
|
||||||
itemId, scheduleId, packageId, maximumExecutionTime, parameters);
|
itemId, scheduleId, packageId, maximumExecutionTime, parameters);
|
||||||
|
@ -170,7 +175,7 @@ namespace WebsitePanel.EnterpriseServer
|
||||||
tasks.Count - 1,
|
tasks.Count - 1,
|
||||||
true,
|
true,
|
||||||
String.Format("{0}_{1}", source, taskName),
|
String.Format("{0}_{1}", source, taskName),
|
||||||
new string[] {itemNameStr});
|
new string[] { itemNameStr });
|
||||||
|
|
||||||
|
|
||||||
TaskController.AddLog(log);
|
TaskController.AddLog(log);
|
||||||
|
@ -234,7 +239,7 @@ namespace WebsitePanel.EnterpriseServer
|
||||||
private static void WriteLogRecord(int severity, string text, string stackTrace, params string[] textParameters)
|
private static void WriteLogRecord(int severity, string text, string stackTrace, params string[] textParameters)
|
||||||
{
|
{
|
||||||
List<BackgroundTask> tasks = TaskController.GetTasks(Guid);
|
List<BackgroundTask> tasks = TaskController.GetTasks(Guid);
|
||||||
|
|
||||||
if (tasks.Count > 0)
|
if (tasks.Count > 0)
|
||||||
{
|
{
|
||||||
BackgroundTask rootTask = tasks[0];
|
BackgroundTask rootTask = tasks[0];
|
||||||
|
@ -287,7 +292,7 @@ namespace WebsitePanel.EnterpriseServer
|
||||||
UserInfo user = UserController.GetUserInternally(topTask.UserId);
|
UserInfo user = UserController.GetUserInternally(topTask.UserId);
|
||||||
string username = user != null ? user.Username : null;
|
string username = user != null ? user.Username : null;
|
||||||
|
|
||||||
AuditLog.AddAuditLogRecord(topTask.TaskId, topTask.Severity, topTask.UserId,
|
AuditLog.AddAuditLogRecord(topTask.TaskId, topTask.Severity, topTask.EffectiveUserId,
|
||||||
username, topTask.PackageId, topTask.ItemId,
|
username, topTask.PackageId, topTask.ItemId,
|
||||||
topTask.ItemName, topTask.StartDate, topTask.FinishDate, topTask.Source,
|
topTask.ItemName, topTask.StartDate, topTask.FinishDate, topTask.Source,
|
||||||
topTask.TaskName, executionLog);
|
topTask.TaskName, executionLog);
|
||||||
|
@ -412,7 +417,7 @@ namespace WebsitePanel.EnterpriseServer
|
||||||
foreach (BackgroundTask task in tasks)
|
foreach (BackgroundTask task in tasks)
|
||||||
{
|
{
|
||||||
if (task.MaximumExecutionTime != -1
|
if (task.MaximumExecutionTime != -1
|
||||||
&& ((TimeSpan) (DateTime.Now - task.StartDate)).TotalSeconds > task.MaximumExecutionTime)
|
&& ((TimeSpan)(DateTime.Now - task.StartDate)).TotalSeconds > task.MaximumExecutionTime)
|
||||||
{
|
{
|
||||||
task.Status = BackgroundTaskStatus.Abort;
|
task.Status = BackgroundTaskStatus.Abort;
|
||||||
|
|
||||||
|
@ -503,7 +508,7 @@ namespace WebsitePanel.EnterpriseServer
|
||||||
public static BackgroundTask GetTaskWithLogRecords(string taskId, DateTime startLogTime)
|
public static BackgroundTask GetTaskWithLogRecords(string taskId, DateTime startLogTime)
|
||||||
{
|
{
|
||||||
BackgroundTask task = GetTask(taskId);
|
BackgroundTask task = GetTask(taskId);
|
||||||
|
|
||||||
if (task == null)
|
if (task == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
|
@ -549,11 +554,11 @@ namespace WebsitePanel.EnterpriseServer
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
task.Status = BackgroundTaskStatus.Abort;
|
task.Status = BackgroundTaskStatus.Abort;
|
||||||
|
|
||||||
StopProcess(task.TaskId);
|
StopProcess(task.TaskId);
|
||||||
|
|
||||||
TaskController.UpdateTask(task);
|
TaskController.UpdateTask(task);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -563,14 +568,14 @@ namespace WebsitePanel.EnterpriseServer
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
task.Status = BackgroundTaskStatus.Abort;
|
task.Status = BackgroundTaskStatus.Abort;
|
||||||
|
|
||||||
StopProcess(task.TaskId);
|
StopProcess(task.TaskId);
|
||||||
|
|
||||||
TaskController.UpdateTask(task);
|
TaskController.UpdateTask(task);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void StopProcess(string taskId)
|
private static void StopProcess(string taskId)
|
||||||
{
|
{
|
||||||
var process = Process.GetProcesses().FirstOrDefault(
|
var process = Process.GetProcesses().FirstOrDefault(
|
||||||
|
@ -595,8 +600,11 @@ namespace WebsitePanel.EnterpriseServer
|
||||||
// get user tasks
|
// get user tasks
|
||||||
foreach (BackgroundTask task in TaskController.GetTasks())
|
foreach (BackgroundTask task in TaskController.GetTasks())
|
||||||
{
|
{
|
||||||
if (task.UserId == userId && !task.Completed)
|
if (task.UserId == userId && !task.Completed
|
||||||
|
&& task.Status == BackgroundTaskStatus.Run)
|
||||||
|
{
|
||||||
list.Add(task);
|
list.Add(task);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
@ -698,7 +706,7 @@ namespace WebsitePanel.EnterpriseServer
|
||||||
List<string> handlersList = (List<string>)eventHandlers[fullTaskName];
|
List<string> handlersList = (List<string>)eventHandlers[fullTaskName];
|
||||||
return handlersList == null ? null : handlersList.ToArray();
|
return handlersList == null ? null : handlersList.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
@ -821,3 +829,4 @@ namespace WebsitePanel.EnterpriseServer
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue