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
|
||||
DELETE FROM HostingPlanQuotas WHERE QuotaID = 340
|
||||
GO
|
||||
|
@ -861,6 +847,7 @@ CREATE TABLE BackgroundTaskParameters
|
|||
TaskID INT NOT NULL,
|
||||
Name NVARCHAR(255),
|
||||
SerializerValue NTEXT,
|
||||
TypeName NVARCHAR(255),
|
||||
FOREIGN KEY (TaskID) REFERENCES BackgroundTasks (ID)
|
||||
)
|
||||
GO
|
||||
|
@ -1074,7 +1061,7 @@ SELECT
|
|||
FROM BackgroundTasks AS T
|
||||
INNER JOIN BackgroundTaskStack AS TS
|
||||
ON TS.TaskId = T.ID
|
||||
WHERE T.UserID = @ActorID AND T.Guid = @Guid
|
||||
WHERE T.EffectiveUserID = @ActorID AND T.Guid = @Guid
|
||||
GO
|
||||
|
||||
IF EXISTS (SELECT * FROM SYS.OBJECTS WHERE type = 'P' AND name = 'GetBackgroundTopTask')
|
||||
|
@ -1112,7 +1099,7 @@ SELECT TOP 1
|
|||
FROM BackgroundTasks AS T
|
||||
INNER JOIN BackgroundTaskStack AS TS
|
||||
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
|
||||
GO
|
||||
|
||||
|
@ -1241,7 +1228,8 @@ SELECT
|
|||
P.ParameterID,
|
||||
P.TaskID,
|
||||
P.Name,
|
||||
P.SerializerValue
|
||||
P.SerializerValue,
|
||||
P.TypeName
|
||||
FROM BackgroundTaskParameters AS P
|
||||
WHERE P.TaskID = @TaskID
|
||||
GO
|
||||
|
@ -1254,7 +1242,8 @@ CREATE PROCEDURE [dbo].[AddBackgroundTaskParam]
|
|||
(
|
||||
@TaskID INT,
|
||||
@Name NVARCHAR(255),
|
||||
@Value NTEXT
|
||||
@Value NTEXT,
|
||||
@TypeName NVARCHAR(255)
|
||||
)
|
||||
AS
|
||||
|
||||
|
@ -1262,13 +1251,15 @@ INSERT INTO BackgroundTaskParameters
|
|||
(
|
||||
TaskID,
|
||||
Name,
|
||||
SerializerValue
|
||||
SerializerValue,
|
||||
TypeName
|
||||
)
|
||||
VALUES
|
||||
(
|
||||
@TaskID,
|
||||
@Name,
|
||||
@Value
|
||||
@Value,
|
||||
@TypeName
|
||||
)
|
||||
GO
|
||||
|
||||
|
|
|
@ -39,6 +39,12 @@ namespace WebsitePanel.EnterpriseServer
|
|||
|
||||
public class BackgroundTask
|
||||
{
|
||||
#region Fields
|
||||
|
||||
private List<BackgroundTaskParameter> parameters;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
public int Id { get; set; }
|
||||
|
@ -83,7 +89,11 @@ namespace WebsitePanel.EnterpriseServer
|
|||
|
||||
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
|
||||
|
||||
|
|
|
@ -1976,13 +1976,14 @@ namespace WebsitePanel.EnterpriseServer
|
|||
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,
|
||||
ObjectQualifier + "AddBackgroundTaskParam",
|
||||
new SqlParameter("@taskId", taskId),
|
||||
new SqlParameter("@name", name),
|
||||
new SqlParameter("@value", value));
|
||||
new SqlParameter("@value", value),
|
||||
new SqlParameter("@typeName", typeName));
|
||||
}
|
||||
|
||||
public static void DeleteBackgroundTaskParams(int taskId)
|
||||
|
|
|
@ -152,10 +152,10 @@ namespace WebsitePanel.EnterpriseServer
|
|||
{
|
||||
// check account
|
||||
int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo);
|
||||
|
||||
|
||||
if (accountCheck < 0)
|
||||
return accountCheck;
|
||||
|
||||
|
||||
SchedulerJob schedule = GetScheduleComplete(scheduleId);
|
||||
if (schedule == null)
|
||||
return 0;
|
||||
|
@ -177,9 +177,9 @@ namespace WebsitePanel.EnterpriseServer
|
|||
schedule.ScheduleInfo.MaxExecutionTime, parameters) { Status = BackgroundTaskStatus.Starting };
|
||||
|
||||
TaskController.AddTask(backgroundTask);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static int StopSchedule(int scheduleId)
|
||||
{
|
||||
|
|
|
@ -109,7 +109,7 @@ namespace WebsitePanel.EnterpriseServer
|
|||
objTask.DoWork();
|
||||
else
|
||||
throw new Exception(String.Format("Could not create scheduled task of '{0}' type",
|
||||
task.TaskType));
|
||||
task.TaskType));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
|
|
@ -88,15 +88,10 @@ namespace WebsitePanel.EnterpriseServer
|
|||
}
|
||||
|
||||
public static void AddTaskParams(int taskId, List<BackgroundTaskParameter> parameters)
|
||||
{
|
||||
if (parameters == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
{
|
||||
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)
|
||||
{
|
||||
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();
|
||||
serializer.Serialize(ms, param.Value);
|
||||
|
||||
|
@ -178,22 +174,17 @@ namespace WebsitePanel.EnterpriseServer
|
|||
|
||||
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);
|
||||
|
||||
if (xmlDoc != null)
|
||||
{
|
||||
int index = 0;
|
||||
foreach (XmlNode xmlParameter in xmlDoc.SelectNodes("parameters/parameter"))
|
||||
{
|
||||
textParameters[index] = xmlParameter.Attributes.GetNamedItem("value").Value;
|
||||
index++;
|
||||
}
|
||||
textParameters.AddRange(from XmlNode xmlParameter in xmlDoc.SelectNodes("parameters/parameter") select xmlParameter.Attributes.GetNamedItem("value").Value);
|
||||
}
|
||||
|
||||
return textParameters;
|
||||
return textParameters.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -141,7 +141,7 @@ namespace WebsitePanel.EnterpriseServer
|
|||
public static void StartTask(string source, string taskName, object itemName, int itemId,
|
||||
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,
|
||||
|
@ -152,8 +152,8 @@ namespace WebsitePanel.EnterpriseServer
|
|||
taskId = Guid.NewGuid().ToString("N");
|
||||
}
|
||||
|
||||
int userId = SecurityContext.User.UserId;
|
||||
int effectiveUserId = SecurityContext.User.IsPeer ? SecurityContext.User.OwnerId : userId;
|
||||
int userId = SecurityContext.User.OwnerId;
|
||||
int effectiveUserId = SecurityContext.User.IsPeer ? SecurityContext.User.OwnerId : SecurityContext.User.UserId;
|
||||
String itemNameStr = itemName != null ? itemName.ToString() : String.Empty;
|
||||
|
||||
BackgroundTask task = new BackgroundTask(Guid, taskId, userId, effectiveUserId, source, taskName, itemNameStr,
|
||||
|
@ -595,7 +595,7 @@ namespace WebsitePanel.EnterpriseServer
|
|||
// get user tasks
|
||||
foreach (BackgroundTask task in TaskController.GetTasks())
|
||||
{
|
||||
if (task.EffectiveUserId == userId && !task.Completed)
|
||||
if (task.UserId == userId && !task.Completed)
|
||||
list.Add(task);
|
||||
}
|
||||
return list;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue