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 static SchedulerJob nextSchedule = null;
|
||||
private static Timer timer = new Timer(ScheduleTasks, null, 30000, 30000);
|
||||
|
||||
public static void Start()
|
||||
{
|
||||
var serviceController = new ServiceController("WebsitePanel Scheduler");
|
||||
|
||||
if (serviceController != null && serviceController.Status != ServiceControllerStatus.Running)
|
||||
{
|
||||
serviceController.WaitForStatus(ServiceControllerStatus.Running);
|
||||
}
|
||||
|
||||
ScheduleTasks(null);
|
||||
ScheduleTasks();
|
||||
}
|
||||
|
||||
public static bool IsScheduleActive(int scheduleId)
|
||||
|
@ -82,6 +76,11 @@ namespace WebsitePanel.EnterpriseServer
|
|||
TaskManager.StopTask(activeTask.TaskId);
|
||||
}
|
||||
|
||||
public static void ScheduleTasks()
|
||||
{
|
||||
ScheduleTasks(null);
|
||||
}
|
||||
|
||||
public static void ScheduleTasks(object obj)
|
||||
{
|
||||
RunManualTasks();
|
||||
|
@ -94,9 +93,6 @@ namespace WebsitePanel.EnterpriseServer
|
|||
RunNextSchedule(null);
|
||||
}
|
||||
}
|
||||
|
||||
Thread.Sleep(30000);
|
||||
ScheduleTasks(null);
|
||||
}
|
||||
|
||||
private static void RunManualTasks()
|
||||
|
@ -162,7 +158,7 @@ namespace WebsitePanel.EnterpriseServer
|
|||
RunSchedule(nextSchedule, true);
|
||||
|
||||
// schedule next task
|
||||
ScheduleTasks(null);
|
||||
ScheduleTasks();
|
||||
}
|
||||
|
||||
static void RunSchedule(SchedulerJob schedule, bool changeNextRun)
|
||||
|
|
|
@ -15,6 +15,11 @@ 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;
|
||||
|
@ -27,9 +32,14 @@ namespace WebsitePanel.EnterpriseServer
|
|||
}
|
||||
|
||||
public static List<BackgroundTask> GetTasks()
|
||||
{
|
||||
return GetTasks(SecurityContext.User.UserId);
|
||||
}
|
||||
|
||||
public static List<BackgroundTask> GetTasks(int actorId)
|
||||
{
|
||||
return ObjectUtils.CreateListFromDataReader<BackgroundTask>(
|
||||
DataProvider.GetBackgroundTasks(SecurityContext.User.UserId));
|
||||
DataProvider.GetBackgroundTasks(actorId));
|
||||
}
|
||||
|
||||
public static List<BackgroundTask> GetTasks(Guid guid)
|
||||
|
@ -49,6 +59,11 @@ namespace WebsitePanel.EnterpriseServer
|
|||
BackgroundTask task = ObjectUtils.FillObjectFromDataReader<BackgroundTask>(
|
||||
DataProvider.GetBackgroundTopTask(SecurityContext.User.UserId, guid));
|
||||
|
||||
if (task == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
task.Params = GetTaskParams(task.Id);
|
||||
|
||||
return task;
|
||||
|
@ -188,3 +203,4 @@ namespace WebsitePanel.EnterpriseServer
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -153,8 +153,13 @@ namespace WebsitePanel.EnterpriseServer
|
|||
}
|
||||
|
||||
int userId = SecurityContext.User.OwnerId;
|
||||
int effectiveUserId = SecurityContext.User.IsPeer ? SecurityContext.User.OwnerId : SecurityContext.User.UserId;
|
||||
String itemNameStr = itemName != null ? itemName.ToString() : String.Empty;
|
||||
int effectiveUserId = SecurityContext.User.IsPeer
|
||||
? userId
|
||||
: SecurityContext.User.UserId;
|
||||
|
||||
String itemNameStr = itemName != null
|
||||
? itemName.ToString()
|
||||
: String.Empty;
|
||||
|
||||
BackgroundTask task = new BackgroundTask(Guid, taskId, userId, effectiveUserId, source, taskName, itemNameStr,
|
||||
itemId, scheduleId, packageId, maximumExecutionTime, parameters);
|
||||
|
@ -287,7 +292,7 @@ namespace WebsitePanel.EnterpriseServer
|
|||
UserInfo user = UserController.GetUserInternally(topTask.UserId);
|
||||
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,
|
||||
topTask.ItemName, topTask.StartDate, topTask.FinishDate, topTask.Source,
|
||||
topTask.TaskName, executionLog);
|
||||
|
@ -595,9 +600,12 @@ namespace WebsitePanel.EnterpriseServer
|
|||
// get user tasks
|
||||
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);
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
|
@ -821,3 +829,4 @@ namespace WebsitePanel.EnterpriseServer
|
|||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue