Scheduler Service fixes
This commit is contained in:
parent
91d9ee7d99
commit
2cf0890e14
6 changed files with 37 additions and 44 deletions
|
@ -12,6 +12,7 @@ BEGIN
|
||||||
END
|
END
|
||||||
GO
|
GO
|
||||||
|
|
||||||
|
|
||||||
--- Fix on version 2.0
|
--- Fix on version 2.0
|
||||||
DELETE FROM HostingPlanQuotas WHERE QuotaID = 340
|
DELETE FROM HostingPlanQuotas WHERE QuotaID = 340
|
||||||
GO
|
GO
|
||||||
|
@ -1329,8 +1330,7 @@ DROP PROCEDURE GetProcessBackgroundTasks
|
||||||
GO
|
GO
|
||||||
|
|
||||||
CREATE PROCEDURE [dbo].[GetProcessBackgroundTasks]
|
CREATE PROCEDURE [dbo].[GetProcessBackgroundTasks]
|
||||||
(
|
(
|
||||||
@ActorID INT,
|
|
||||||
@Status INT
|
@Status INT
|
||||||
)
|
)
|
||||||
AS
|
AS
|
||||||
|
@ -1356,7 +1356,7 @@ SELECT
|
||||||
T.NotifyOnComplete,
|
T.NotifyOnComplete,
|
||||||
T.Status
|
T.Status
|
||||||
FROM BackgroundTasks AS T
|
FROM BackgroundTasks AS T
|
||||||
WHERE T.UserID = @ActorID AND T.Completed = 0 AND T.Status = @Status
|
WHERE T.Completed = 0 AND T.Status = @Status
|
||||||
GO
|
GO
|
||||||
|
|
||||||
IF EXISTS (SELECT * FROM SYS.OBJECTS WHERE type = 'P' AND name = 'GetScheduleBackgroundTasks')
|
IF EXISTS (SELECT * FROM SYS.OBJECTS WHERE type = 'P' AND name = 'GetScheduleBackgroundTasks')
|
||||||
|
|
|
@ -1868,11 +1868,10 @@ namespace WebsitePanel.EnterpriseServer
|
||||||
new SqlParameter("@guid", guid));
|
new SqlParameter("@guid", guid));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IDataReader GetProcessBackgroundTasks(int actorId, BackgroundTaskStatus status)
|
public static IDataReader GetProcessBackgroundTasks(BackgroundTaskStatus status)
|
||||||
{
|
{
|
||||||
return SqlHelper.ExecuteReader(ConnectionString, CommandType.StoredProcedure,
|
return SqlHelper.ExecuteReader(ConnectionString, CommandType.StoredProcedure,
|
||||||
ObjectQualifier + "GetProcessBackgroundTasks",
|
ObjectQualifier + "GetProcessBackgroundTasks",
|
||||||
new SqlParameter("@actorId", actorId),
|
|
||||||
new SqlParameter("@status", (int)status));
|
new SqlParameter("@status", (int)status));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.ServiceProcess;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
@ -41,18 +42,18 @@ namespace WebsitePanel.EnterpriseServer
|
||||||
|
|
||||||
public sealed class Scheduler
|
public sealed class Scheduler
|
||||||
{
|
{
|
||||||
public static SchedulerJob nextSchedule = null;
|
public static SchedulerJob nextSchedule = null;
|
||||||
|
|
||||||
// main timer and put it to sleep
|
|
||||||
static Timer scheduleTimer = new Timer(new TimerCallback(RunNextSchedule),
|
|
||||||
null,
|
|
||||||
Timeout.Infinite,
|
|
||||||
Timeout.Infinite);
|
|
||||||
|
|
||||||
public static void Start()
|
public static void Start()
|
||||||
{
|
{
|
||||||
// schedule tasks
|
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)
|
||||||
|
@ -81,43 +82,34 @@ namespace WebsitePanel.EnterpriseServer
|
||||||
TaskManager.StopTask(activeTask.TaskId);
|
TaskManager.StopTask(activeTask.TaskId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void ScheduleTasks()
|
public static void ScheduleTasks(object obj)
|
||||||
{
|
{
|
||||||
RunManualTasks();
|
RunManualTasks();
|
||||||
|
nextSchedule = SchedulerController.GetNextSchedule();
|
||||||
nextSchedule = SchedulerController.GetNextSchedule();
|
|
||||||
|
|
||||||
// set timer
|
|
||||||
if (nextSchedule != null)
|
if (nextSchedule != null)
|
||||||
{
|
{
|
||||||
if (nextSchedule.ScheduleInfo.NextRun <= DateTime.Now)
|
if (nextSchedule.ScheduleInfo.NextRun <= DateTime.Now)
|
||||||
{
|
{
|
||||||
// this will put the timer to sleep
|
|
||||||
scheduleTimer.Change(Timeout.Infinite, Timeout.Infinite);
|
|
||||||
Thread.Sleep(1000);
|
|
||||||
// run immediately
|
|
||||||
RunNextSchedule(null);
|
RunNextSchedule(null);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
// set timer
|
|
||||||
TimeSpan ts = nextSchedule.ScheduleInfo.NextRun.Subtract(DateTime.Now);
|
|
||||||
if (ts < TimeSpan.Zero)
|
|
||||||
ts = TimeSpan.Zero; // cannot be negative !
|
|
||||||
// invoke after the timespan
|
|
||||||
scheduleTimer.Change((long)ts.TotalMilliseconds, Timeout.Infinite);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Thread.Sleep(30000);
|
||||||
|
ScheduleTasks(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void RunManualTasks()
|
private static void RunManualTasks()
|
||||||
{
|
{
|
||||||
var tasks = TaskController.GetProcessTasks(BackgroundTaskStatus.Starting);
|
var tasks = TaskController.GetProcessTasks(BackgroundTaskStatus.Starting);
|
||||||
|
|
||||||
foreach (var task in tasks)
|
foreach (var task in tasks)
|
||||||
{
|
{
|
||||||
new Thread(() => RunBackgroundTask(task)) {Priority = ThreadPriority.Highest}.Start();
|
new Thread(() => RunBackgroundTask(task)) {Priority = ThreadPriority.Highest}.Start();
|
||||||
}
|
}
|
||||||
tasks = TaskController.GetProcessTasks(BackgroundTaskStatus.Stopping);
|
|
||||||
|
tasks = TaskController.GetProcessTasks(BackgroundTaskStatus.Stopping);
|
||||||
|
|
||||||
foreach (var task in tasks)
|
foreach (var task in tasks)
|
||||||
{
|
{
|
||||||
TaskManager.StopTask(task);
|
TaskManager.StopTask(task);
|
||||||
|
@ -170,7 +162,7 @@ namespace WebsitePanel.EnterpriseServer
|
||||||
RunSchedule(nextSchedule, true);
|
RunSchedule(nextSchedule, true);
|
||||||
|
|
||||||
// schedule next task
|
// schedule next task
|
||||||
ScheduleTasks();
|
ScheduleTasks(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void RunSchedule(SchedulerJob schedule, bool changeNextRun)
|
static void RunSchedule(SchedulerJob schedule, bool changeNextRun)
|
||||||
|
|
|
@ -41,7 +41,7 @@ namespace WebsitePanel.EnterpriseServer
|
||||||
public static List<BackgroundTask> GetProcessTasks(BackgroundTaskStatus status)
|
public static List<BackgroundTask> GetProcessTasks(BackgroundTaskStatus status)
|
||||||
{
|
{
|
||||||
return ObjectUtils.CreateListFromDataReader<BackgroundTask>(
|
return ObjectUtils.CreateListFromDataReader<BackgroundTask>(
|
||||||
DataProvider.GetProcessBackgroundTasks(SecurityContext.User.UserId, status));
|
DataProvider.GetProcessBackgroundTasks(status));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BackgroundTask GetTopTask(Guid guid)
|
public static BackgroundTask GetTopTask(Guid guid)
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
|
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||||
<DebugType>pdbonly</DebugType>
|
<DebugType>pdbonly</DebugType>
|
||||||
|
@ -42,6 +43,7 @@
|
||||||
<Reference Include="System.Core" />
|
<Reference Include="System.Core" />
|
||||||
<Reference Include="System.DirectoryServices" />
|
<Reference Include="System.DirectoryServices" />
|
||||||
<Reference Include="System.Security" />
|
<Reference Include="System.Security" />
|
||||||
|
<Reference Include="System.ServiceProcess" />
|
||||||
<Reference Include="System.Web" />
|
<Reference Include="System.Web" />
|
||||||
<Reference Include="System.Web.Services" />
|
<Reference Include="System.Web.Services" />
|
||||||
<Reference Include="System.Xml.Linq" />
|
<Reference Include="System.Xml.Linq" />
|
||||||
|
|
|
@ -17,7 +17,7 @@ namespace WebsitePanel.SchedulerService
|
||||||
processInstaller.Account = ServiceAccount.LocalSystem;
|
processInstaller.Account = ServiceAccount.LocalSystem;
|
||||||
serviceInstaller.DisplayName = "WebsitePanel Scheduler";
|
serviceInstaller.DisplayName = "WebsitePanel Scheduler";
|
||||||
serviceInstaller.StartType = ServiceStartMode.Automatic;
|
serviceInstaller.StartType = ServiceStartMode.Automatic;
|
||||||
serviceInstaller.ServiceName = "WebsitePanlel Scheduler";
|
serviceInstaller.ServiceName = "WebsitePanel Scheduler";
|
||||||
|
|
||||||
Installers.Add(processInstaller);
|
Installers.Add(processInstaller);
|
||||||
Installers.Add(serviceInstaller);
|
Installers.Add(serviceInstaller);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue