Scheduler service fixes
This commit is contained in:
parent
2cf0890e14
commit
bcceb95f92
3 changed files with 62 additions and 41 deletions
|
@ -43,17 +43,11 @@ 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,6 +76,11 @@ 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();
|
||||||
|
@ -94,9 +93,6 @@ namespace WebsitePanel.EnterpriseServer
|
||||||
RunNextSchedule(null);
|
RunNextSchedule(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Thread.Sleep(30000);
|
|
||||||
ScheduleTasks(null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void RunManualTasks()
|
private static void RunManualTasks()
|
||||||
|
@ -162,7 +158,7 @@ namespace WebsitePanel.EnterpriseServer
|
||||||
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;
|
||||||
|
@ -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);
|
||||||
|
@ -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);
|
||||||
|
@ -595,9 +600,12 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -821,3 +829,4 @@ namespace WebsitePanel.EnterpriseServer
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue