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
|
||||
GO
|
||||
|
||||
|
||||
--- Fix on version 2.0
|
||||
DELETE FROM HostingPlanQuotas WHERE QuotaID = 340
|
||||
GO
|
||||
|
@ -1329,8 +1330,7 @@ DROP PROCEDURE GetProcessBackgroundTasks
|
|||
GO
|
||||
|
||||
CREATE PROCEDURE [dbo].[GetProcessBackgroundTasks]
|
||||
(
|
||||
@ActorID INT,
|
||||
(
|
||||
@Status INT
|
||||
)
|
||||
AS
|
||||
|
@ -1356,7 +1356,7 @@ SELECT
|
|||
T.NotifyOnComplete,
|
||||
T.Status
|
||||
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
|
||||
|
||||
IF EXISTS (SELECT * FROM SYS.OBJECTS WHERE type = 'P' AND name = 'GetScheduleBackgroundTasks')
|
||||
|
|
|
@ -1868,11 +1868,10 @@ namespace WebsitePanel.EnterpriseServer
|
|||
new SqlParameter("@guid", guid));
|
||||
}
|
||||
|
||||
public static IDataReader GetProcessBackgroundTasks(int actorId, BackgroundTaskStatus status)
|
||||
public static IDataReader GetProcessBackgroundTasks(BackgroundTaskStatus status)
|
||||
{
|
||||
return SqlHelper.ExecuteReader(ConnectionString, CommandType.StoredProcedure,
|
||||
ObjectQualifier + "GetProcessBackgroundTasks",
|
||||
new SqlParameter("@actorId", actorId),
|
||||
ObjectQualifier + "GetProcessBackgroundTasks",
|
||||
new SqlParameter("@status", (int)status));
|
||||
}
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.ServiceProcess;
|
||||
using System.Threading;
|
||||
using System.Collections;
|
||||
using System.Diagnostics;
|
||||
|
@ -41,18 +42,18 @@ namespace WebsitePanel.EnterpriseServer
|
|||
|
||||
public sealed class Scheduler
|
||||
{
|
||||
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 SchedulerJob nextSchedule = null;
|
||||
|
||||
public static void Start()
|
||||
{
|
||||
// schedule tasks
|
||||
ScheduleTasks();
|
||||
{
|
||||
var serviceController = new ServiceController("WebsitePanel Scheduler");
|
||||
|
||||
if (serviceController != null && serviceController.Status != ServiceControllerStatus.Running)
|
||||
{
|
||||
serviceController.WaitForStatus(ServiceControllerStatus.Running);
|
||||
}
|
||||
|
||||
ScheduleTasks(null);
|
||||
}
|
||||
|
||||
public static bool IsScheduleActive(int scheduleId)
|
||||
|
@ -81,43 +82,34 @@ namespace WebsitePanel.EnterpriseServer
|
|||
TaskManager.StopTask(activeTask.TaskId);
|
||||
}
|
||||
|
||||
public static void ScheduleTasks()
|
||||
{
|
||||
RunManualTasks();
|
||||
|
||||
nextSchedule = SchedulerController.GetNextSchedule();
|
||||
|
||||
// set timer
|
||||
public static void ScheduleTasks(object obj)
|
||||
{
|
||||
RunManualTasks();
|
||||
nextSchedule = SchedulerController.GetNextSchedule();
|
||||
|
||||
if (nextSchedule != null)
|
||||
{
|
||||
{
|
||||
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);
|
||||
}
|
||||
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()
|
||||
{
|
||||
var tasks = TaskController.GetProcessTasks(BackgroundTaskStatus.Starting);
|
||||
var tasks = TaskController.GetProcessTasks(BackgroundTaskStatus.Starting);
|
||||
|
||||
foreach (var task in tasks)
|
||||
{
|
||||
new Thread(() => RunBackgroundTask(task)) {Priority = ThreadPriority.Highest}.Start();
|
||||
}
|
||||
tasks = TaskController.GetProcessTasks(BackgroundTaskStatus.Stopping);
|
||||
|
||||
tasks = TaskController.GetProcessTasks(BackgroundTaskStatus.Stopping);
|
||||
|
||||
foreach (var task in tasks)
|
||||
{
|
||||
TaskManager.StopTask(task);
|
||||
|
@ -170,7 +162,7 @@ namespace WebsitePanel.EnterpriseServer
|
|||
RunSchedule(nextSchedule, true);
|
||||
|
||||
// schedule next task
|
||||
ScheduleTasks();
|
||||
ScheduleTasks(null);
|
||||
}
|
||||
|
||||
static void RunSchedule(SchedulerJob schedule, bool changeNextRun)
|
||||
|
|
|
@ -41,7 +41,7 @@ namespace WebsitePanel.EnterpriseServer
|
|||
public static List<BackgroundTask> GetProcessTasks(BackgroundTaskStatus status)
|
||||
{
|
||||
return ObjectUtils.CreateListFromDataReader<BackgroundTask>(
|
||||
DataProvider.GetProcessBackgroundTasks(SecurityContext.User.UserId, status));
|
||||
DataProvider.GetProcessBackgroundTasks(status));
|
||||
}
|
||||
|
||||
public static BackgroundTask GetTopTask(Guid guid)
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
|
@ -42,6 +43,7 @@
|
|||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.DirectoryServices" />
|
||||
<Reference Include="System.Security" />
|
||||
<Reference Include="System.ServiceProcess" />
|
||||
<Reference Include="System.Web" />
|
||||
<Reference Include="System.Web.Services" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
|
|
|
@ -17,7 +17,7 @@ namespace WebsitePanel.SchedulerService
|
|||
processInstaller.Account = ServiceAccount.LocalSystem;
|
||||
serviceInstaller.DisplayName = "WebsitePanel Scheduler";
|
||||
serviceInstaller.StartType = ServiceStartMode.Automatic;
|
||||
serviceInstaller.ServiceName = "WebsitePanlel Scheduler";
|
||||
serviceInstaller.ServiceName = "WebsitePanel Scheduler";
|
||||
|
||||
Installers.Add(processInstaller);
|
||||
Installers.Add(serviceInstaller);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue