Testing and fixing scheduler
This commit is contained in:
parent
20f4b371d1
commit
b2d9fb43b2
7 changed files with 44 additions and 51 deletions
|
@ -1,18 +1,4 @@
|
||||||
USE [${install.database}]
|
|
||||||
GO
|
|
||||||
|
|
||||||
-- update database version
|
|
||||||
DECLARE @build_version nvarchar(10), @build_date datetime
|
|
||||||
SET @build_version = N'${release.version}'
|
|
||||||
SET @build_date = '${release.date}T00:00:00' -- ISO 8601 Format (YYYY-MM-DDTHH:MM:SS)
|
|
||||||
|
|
||||||
IF NOT EXISTS (SELECT * FROM [dbo].[Versions] WHERE [DatabaseVersion] = @build_version)
|
|
||||||
BEGIN
|
|
||||||
INSERT [dbo].[Versions] ([DatabaseVersion], [BuildDate]) VALUES (@build_version, @build_date)
|
|
||||||
END
|
|
||||||
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
|
||||||
|
@ -861,6 +847,7 @@ CREATE TABLE BackgroundTaskParameters
|
||||||
TaskID INT NOT NULL,
|
TaskID INT NOT NULL,
|
||||||
Name NVARCHAR(255),
|
Name NVARCHAR(255),
|
||||||
SerializerValue NTEXT,
|
SerializerValue NTEXT,
|
||||||
|
TypeName NVARCHAR(255),
|
||||||
FOREIGN KEY (TaskID) REFERENCES BackgroundTasks (ID)
|
FOREIGN KEY (TaskID) REFERENCES BackgroundTasks (ID)
|
||||||
)
|
)
|
||||||
GO
|
GO
|
||||||
|
@ -1074,7 +1061,7 @@ SELECT
|
||||||
FROM BackgroundTasks AS T
|
FROM BackgroundTasks AS T
|
||||||
INNER JOIN BackgroundTaskStack AS TS
|
INNER JOIN BackgroundTaskStack AS TS
|
||||||
ON TS.TaskId = T.ID
|
ON TS.TaskId = T.ID
|
||||||
WHERE T.UserID = @ActorID AND T.Guid = @Guid
|
WHERE T.EffectiveUserID = @ActorID AND T.Guid = @Guid
|
||||||
GO
|
GO
|
||||||
|
|
||||||
IF EXISTS (SELECT * FROM SYS.OBJECTS WHERE type = 'P' AND name = 'GetBackgroundTopTask')
|
IF EXISTS (SELECT * FROM SYS.OBJECTS WHERE type = 'P' AND name = 'GetBackgroundTopTask')
|
||||||
|
@ -1112,7 +1099,7 @@ SELECT TOP 1
|
||||||
FROM BackgroundTasks AS T
|
FROM BackgroundTasks AS T
|
||||||
INNER JOIN BackgroundTaskStack AS TS
|
INNER JOIN BackgroundTaskStack AS TS
|
||||||
ON TS.TaskId = T.ID
|
ON TS.TaskId = T.ID
|
||||||
WHERE T.UserID = @ActorID AND T.Guid = @Guid
|
WHERE T.EffectiveUserID = @ActorID AND T.Guid = @Guid
|
||||||
ORDER BY T.StartDate DESC
|
ORDER BY T.StartDate DESC
|
||||||
GO
|
GO
|
||||||
|
|
||||||
|
@ -1241,7 +1228,8 @@ SELECT
|
||||||
P.ParameterID,
|
P.ParameterID,
|
||||||
P.TaskID,
|
P.TaskID,
|
||||||
P.Name,
|
P.Name,
|
||||||
P.SerializerValue
|
P.SerializerValue,
|
||||||
|
P.TypeName
|
||||||
FROM BackgroundTaskParameters AS P
|
FROM BackgroundTaskParameters AS P
|
||||||
WHERE P.TaskID = @TaskID
|
WHERE P.TaskID = @TaskID
|
||||||
GO
|
GO
|
||||||
|
@ -1254,7 +1242,8 @@ CREATE PROCEDURE [dbo].[AddBackgroundTaskParam]
|
||||||
(
|
(
|
||||||
@TaskID INT,
|
@TaskID INT,
|
||||||
@Name NVARCHAR(255),
|
@Name NVARCHAR(255),
|
||||||
@Value NTEXT
|
@Value NTEXT,
|
||||||
|
@TypeName NVARCHAR(255)
|
||||||
)
|
)
|
||||||
AS
|
AS
|
||||||
|
|
||||||
|
@ -1262,13 +1251,15 @@ INSERT INTO BackgroundTaskParameters
|
||||||
(
|
(
|
||||||
TaskID,
|
TaskID,
|
||||||
Name,
|
Name,
|
||||||
SerializerValue
|
SerializerValue,
|
||||||
|
TypeName
|
||||||
)
|
)
|
||||||
VALUES
|
VALUES
|
||||||
(
|
(
|
||||||
@TaskID,
|
@TaskID,
|
||||||
@Name,
|
@Name,
|
||||||
@Value
|
@Value,
|
||||||
|
@TypeName
|
||||||
)
|
)
|
||||||
GO
|
GO
|
||||||
|
|
||||||
|
|
|
@ -39,6 +39,12 @@ namespace WebsitePanel.EnterpriseServer
|
||||||
|
|
||||||
public class BackgroundTask
|
public class BackgroundTask
|
||||||
{
|
{
|
||||||
|
#region Fields
|
||||||
|
|
||||||
|
private List<BackgroundTaskParameter> parameters;
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region Properties
|
#region Properties
|
||||||
|
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
|
@ -83,7 +89,11 @@ namespace WebsitePanel.EnterpriseServer
|
||||||
|
|
||||||
public List<BackgroundTaskLogRecord> Logs { get; set; }
|
public List<BackgroundTaskLogRecord> Logs { get; set; }
|
||||||
|
|
||||||
public List<BackgroundTaskParameter> Params { get; set; }
|
public List<BackgroundTaskParameter> Params
|
||||||
|
{
|
||||||
|
get { return parameters ?? (parameters = new List<BackgroundTaskParameter>()); }
|
||||||
|
set { parameters = value; }
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
|
@ -1976,13 +1976,14 @@ namespace WebsitePanel.EnterpriseServer
|
||||||
new SqlParameter("@taskId", taskId));
|
new SqlParameter("@taskId", taskId));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void AddBackgroundTaskParam(int taskId, string name, string value)
|
public static void AddBackgroundTaskParam(int taskId, string name, string value, string typeName)
|
||||||
{
|
{
|
||||||
SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure,
|
SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure,
|
||||||
ObjectQualifier + "AddBackgroundTaskParam",
|
ObjectQualifier + "AddBackgroundTaskParam",
|
||||||
new SqlParameter("@taskId", taskId),
|
new SqlParameter("@taskId", taskId),
|
||||||
new SqlParameter("@name", name),
|
new SqlParameter("@name", name),
|
||||||
new SqlParameter("@value", value));
|
new SqlParameter("@value", value),
|
||||||
|
new SqlParameter("@typeName", typeName));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void DeleteBackgroundTaskParams(int taskId)
|
public static void DeleteBackgroundTaskParams(int taskId)
|
||||||
|
|
|
@ -152,10 +152,10 @@ namespace WebsitePanel.EnterpriseServer
|
||||||
{
|
{
|
||||||
// check account
|
// check account
|
||||||
int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo);
|
int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo);
|
||||||
|
|
||||||
if (accountCheck < 0)
|
if (accountCheck < 0)
|
||||||
return accountCheck;
|
return accountCheck;
|
||||||
|
|
||||||
SchedulerJob schedule = GetScheduleComplete(scheduleId);
|
SchedulerJob schedule = GetScheduleComplete(scheduleId);
|
||||||
if (schedule == null)
|
if (schedule == null)
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -177,9 +177,9 @@ namespace WebsitePanel.EnterpriseServer
|
||||||
schedule.ScheduleInfo.MaxExecutionTime, parameters) { Status = BackgroundTaskStatus.Starting };
|
schedule.ScheduleInfo.MaxExecutionTime, parameters) { Status = BackgroundTaskStatus.Starting };
|
||||||
|
|
||||||
TaskController.AddTask(backgroundTask);
|
TaskController.AddTask(backgroundTask);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int StopSchedule(int scheduleId)
|
public static int StopSchedule(int scheduleId)
|
||||||
{
|
{
|
||||||
|
|
|
@ -109,7 +109,7 @@ namespace WebsitePanel.EnterpriseServer
|
||||||
objTask.DoWork();
|
objTask.DoWork();
|
||||||
else
|
else
|
||||||
throw new Exception(String.Format("Could not create scheduled task of '{0}' type",
|
throw new Exception(String.Format("Could not create scheduled task of '{0}' type",
|
||||||
task.TaskType));
|
task.TaskType));
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|
|
@ -88,15 +88,10 @@ namespace WebsitePanel.EnterpriseServer
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void AddTaskParams(int taskId, List<BackgroundTaskParameter> parameters)
|
public static void AddTaskParams(int taskId, List<BackgroundTaskParameter> parameters)
|
||||||
{
|
{
|
||||||
if (parameters == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (BackgroundTaskParameter param in SerializeParams(parameters))
|
foreach (BackgroundTaskParameter param in SerializeParams(parameters))
|
||||||
{
|
{
|
||||||
DataProvider.AddBackgroundTaskParam(taskId, param.Name, param.SerializerValue);
|
DataProvider.AddBackgroundTaskParam(taskId, param.Name, param.SerializerValue, param.TypeName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,9 +126,10 @@ namespace WebsitePanel.EnterpriseServer
|
||||||
{
|
{
|
||||||
foreach (BackgroundTaskParameter param in parameters)
|
foreach (BackgroundTaskParameter param in parameters)
|
||||||
{
|
{
|
||||||
param.TypeName = param.Value.GetType().Name;
|
var type = param.Value.GetType();
|
||||||
|
param.TypeName = type.FullName;
|
||||||
|
|
||||||
XmlSerializer serializer = new XmlSerializer(Type.GetType(param.TypeName));
|
XmlSerializer serializer = new XmlSerializer(type);
|
||||||
MemoryStream ms = new MemoryStream();
|
MemoryStream ms = new MemoryStream();
|
||||||
serializer.Serialize(ms, param.Value);
|
serializer.Serialize(ms, param.Value);
|
||||||
|
|
||||||
|
@ -178,22 +174,17 @@ namespace WebsitePanel.EnterpriseServer
|
||||||
|
|
||||||
private static string[] ReBuildParametersXml(string parameters)
|
private static string[] ReBuildParametersXml(string parameters)
|
||||||
{
|
{
|
||||||
string[] textParameters = new string[] {};
|
var textParameters = new List<string>();
|
||||||
|
|
||||||
XmlDocument xmlDoc = new XmlDocument();
|
var xmlDoc = new XmlDocument();
|
||||||
xmlDoc.LoadXml(parameters);
|
xmlDoc.LoadXml(parameters);
|
||||||
|
|
||||||
if (xmlDoc != null)
|
if (xmlDoc != null)
|
||||||
{
|
{
|
||||||
int index = 0;
|
textParameters.AddRange(from XmlNode xmlParameter in xmlDoc.SelectNodes("parameters/parameter") select xmlParameter.Attributes.GetNamedItem("value").Value);
|
||||||
foreach (XmlNode xmlParameter in xmlDoc.SelectNodes("parameters/parameter"))
|
|
||||||
{
|
|
||||||
textParameters[index] = xmlParameter.Attributes.GetNamedItem("value").Value;
|
|
||||||
index++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return textParameters;
|
return textParameters.ToArray();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -141,7 +141,7 @@ namespace WebsitePanel.EnterpriseServer
|
||||||
public static void StartTask(string source, string taskName, object itemName, int itemId,
|
public static void StartTask(string source, string taskName, object itemName, int itemId,
|
||||||
int scheduleId, int packageId, int maximumExecutionTime, List<BackgroundTaskParameter> parameters)
|
int scheduleId, int packageId, int maximumExecutionTime, List<BackgroundTaskParameter> parameters)
|
||||||
{
|
{
|
||||||
StartTask(null, source, taskName, itemName, itemId, scheduleId, packageId, maximumExecutionTime, new List<BackgroundTaskParameter>());
|
StartTask(null, source, taskName, itemName, itemId, scheduleId, packageId, maximumExecutionTime, parameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void StartTask(string taskId, string source, string taskName, object itemName, int itemId,
|
public static void StartTask(string taskId, string source, string taskName, object itemName, int itemId,
|
||||||
|
@ -152,8 +152,8 @@ namespace WebsitePanel.EnterpriseServer
|
||||||
taskId = Guid.NewGuid().ToString("N");
|
taskId = Guid.NewGuid().ToString("N");
|
||||||
}
|
}
|
||||||
|
|
||||||
int userId = SecurityContext.User.UserId;
|
int userId = SecurityContext.User.OwnerId;
|
||||||
int effectiveUserId = SecurityContext.User.IsPeer ? SecurityContext.User.OwnerId : userId;
|
int effectiveUserId = SecurityContext.User.IsPeer ? SecurityContext.User.OwnerId : SecurityContext.User.UserId;
|
||||||
String itemNameStr = itemName != null ? itemName.ToString() : String.Empty;
|
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,
|
||||||
|
@ -595,7 +595,7 @@ namespace WebsitePanel.EnterpriseServer
|
||||||
// get user tasks
|
// get user tasks
|
||||||
foreach (BackgroundTask task in TaskController.GetTasks())
|
foreach (BackgroundTask task in TaskController.GetTasks())
|
||||||
{
|
{
|
||||||
if (task.EffectiveUserId == userId && !task.Completed)
|
if (task.UserId == userId && !task.Completed)
|
||||||
list.Add(task);
|
list.Add(task);
|
||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue