fixed bug with "Running Tasks"
This commit is contained in:
parent
9a10d75492
commit
b9cde075d6
7 changed files with 584 additions and 434 deletions
|
@ -813,4 +813,48 @@ GO
|
|||
|
||||
UPDATE ScheduleTasks SET TaskType = RTRIM(TaskType) + '.Code'
|
||||
WHERE SUBSTRING(RTRIM(TaskType), LEN(RTRIM(TaskType)) - 3, 4) <> 'Code'
|
||||
GO
|
||||
|
||||
IF EXISTS (SELECT * FROM sys.objects WHERE type = 'P' AND name = 'GetRunningSchedules')
|
||||
DROP PROCEDURE GetRunningSchedules
|
||||
GO
|
||||
|
||||
CREATE PROCEDURE [dbo].[GetRunningSchedules]
|
||||
(
|
||||
@ActorID int
|
||||
)
|
||||
AS
|
||||
|
||||
SELECT
|
||||
S.ScheduleID,
|
||||
S.TaskID,
|
||||
ST.TaskType,
|
||||
ST.RoleID,
|
||||
S.PackageID,
|
||||
S.ScheduleName,
|
||||
S.ScheduleTypeID,
|
||||
S.Interval,
|
||||
S.FromTime,
|
||||
S.ToTime,
|
||||
S.StartTime,
|
||||
S.LastRun,
|
||||
S.LastFinish,
|
||||
S.NextRun,
|
||||
S.Enabled,
|
||||
1 AS StatusID,
|
||||
S.PriorityID,
|
||||
S.MaxExecutionTime,
|
||||
S.WeekMonthDay,
|
||||
ISNULL(0, (SELECT TOP 1 SeverityID FROM AuditLog WHERE ItemID = S.ScheduleID AND SourceName = 'SCHEDULER' ORDER BY StartDate DESC)) AS LastResult,
|
||||
U.Username,
|
||||
U.FirstName,
|
||||
U.LastName,
|
||||
U.FullName,
|
||||
U.RoleID,
|
||||
U.Email
|
||||
FROM Schedule AS S
|
||||
INNER JOIN Packages AS P ON S.PackageID = P.PackageID
|
||||
INNER JOIN ScheduleTasks AS ST ON S.TaskID = ST.TaskID
|
||||
INNER JOIN UsersDetailed AS U ON P.UserID = U.UserID
|
||||
WHERE (U.UserID = @ActorID OR U.OwnerID = @ActorID) AND S.LastRun > S.LastFinish
|
||||
GO
|
File diff suppressed because it is too large
Load diff
|
@ -54,6 +54,12 @@ namespace WebsitePanel.EnterpriseServer
|
|||
DataProvider.GetScheduleTask(SecurityContext.User.UserId, taskId));
|
||||
}
|
||||
|
||||
public static List<ScheduleInfo> GetRunningSchedules()
|
||||
{
|
||||
return ObjectUtils.CreateListFromDataReader<ScheduleInfo>(
|
||||
DataProvider.GetRunningSchedules(SecurityContext.User.UserId));
|
||||
}
|
||||
|
||||
public static DataSet GetSchedules(int packageId)
|
||||
{
|
||||
DataSet ds = DataProvider.GetSchedules(SecurityContext.User.UserId, packageId);
|
||||
|
|
|
@ -134,13 +134,13 @@ namespace WebsitePanel.EnterpriseServer
|
|||
WriteLogRecord(0, parameterName + ": " + val, null, null);
|
||||
}
|
||||
|
||||
public static void Write(string text, params string[] textParameters)
|
||||
public static void Write(string text, params string[] textParameters)
|
||||
{
|
||||
// INFO
|
||||
WriteLogRecord(0, text, null, textParameters);
|
||||
}
|
||||
|
||||
public static void WriteWarning(string text, params string[] textParameters)
|
||||
public static void WriteWarning(string text, params string[] textParameters)
|
||||
{
|
||||
// WARNING
|
||||
WriteLogRecord(1, text, null, textParameters);
|
||||
|
@ -168,7 +168,7 @@ namespace WebsitePanel.EnterpriseServer
|
|||
WriteLogRecord(2, text, ex.Message + "\n" + ex.StackTrace, prms);
|
||||
}
|
||||
|
||||
public static void WriteError(string text, params string[] textParameters)
|
||||
public static void WriteError(string text, params string[] textParameters)
|
||||
{
|
||||
// ERROR
|
||||
WriteLogRecord(2, text, null, textParameters);
|
||||
|
@ -195,8 +195,8 @@ namespace WebsitePanel.EnterpriseServer
|
|||
|
||||
public static void CompleteTask()
|
||||
{
|
||||
if (TasksStack.Count == 0)
|
||||
return;
|
||||
if (TasksStack.Count == 0)
|
||||
return;
|
||||
|
||||
// call event handler
|
||||
CallTaskEventHandler(TopTask, true);
|
||||
|
@ -241,7 +241,7 @@ namespace WebsitePanel.EnterpriseServer
|
|||
XmlWriter writer = new XmlTextWriter(sw);
|
||||
|
||||
writer.WriteStartElement("log");
|
||||
|
||||
|
||||
// parameters
|
||||
writer.WriteStartElement("parameters");
|
||||
foreach (string name in task.Parameters.Keys)
|
||||
|
@ -320,7 +320,21 @@ namespace WebsitePanel.EnterpriseServer
|
|||
|
||||
// remove tasks
|
||||
foreach (string taskId in completedTasks)
|
||||
{
|
||||
BackgroundTask task = GetTask(taskId);
|
||||
if (task != null)
|
||||
{
|
||||
// update last finish time
|
||||
SchedulerJob schedule = SchedulerController.GetScheduleComplete(task.ItemId);
|
||||
if (schedule != null)
|
||||
{
|
||||
schedule.ScheduleInfo.LastFinish = DateTime.Now;
|
||||
SchedulerController.UpdateSchedule(schedule.ScheduleInfo);
|
||||
}
|
||||
}
|
||||
|
||||
tasks.Remove(taskId);
|
||||
}
|
||||
}
|
||||
|
||||
public static int PackageId
|
||||
|
@ -449,6 +463,14 @@ namespace WebsitePanel.EnterpriseServer
|
|||
// nope
|
||||
}
|
||||
|
||||
// update last finish time
|
||||
SchedulerJob schedule = SchedulerController.GetScheduleComplete(task.ItemId);
|
||||
if (schedule != null)
|
||||
{
|
||||
schedule.ScheduleInfo.LastFinish = DateTime.Now;
|
||||
SchedulerController.UpdateSchedule(schedule.ScheduleInfo);
|
||||
}
|
||||
|
||||
// remove it from stack
|
||||
tasks.Remove(taskId);
|
||||
}
|
||||
|
@ -467,17 +489,37 @@ namespace WebsitePanel.EnterpriseServer
|
|||
{
|
||||
List<BackgroundTask> list = new List<BackgroundTask>();
|
||||
|
||||
// try to get user first
|
||||
UserInfo user = UserController.GetUser(userId);
|
||||
if (user == null)
|
||||
return list; // prohibited user
|
||||
int effectiveUserId = SecurityContext.User.IsPeer ? SecurityContext.User.OwnerId : SecurityContext.User.UserId;
|
||||
Dictionary<int, BackgroundTask> scheduledTasks = GetScheduledTasks();
|
||||
|
||||
// get user tasks
|
||||
foreach (BackgroundTask task in tasks.Values)
|
||||
List<ScheduleInfo> scheduleList = SchedulerController.GetRunningSchedules();
|
||||
|
||||
foreach (var scheduleInfo in scheduleList)
|
||||
{
|
||||
if(task.EffectiveUserId == userId && !task.Completed)
|
||||
list.Add(task);
|
||||
if (effectiveUserId == userId && scheduleInfo.LastRun > scheduleInfo.LastFinish)
|
||||
{
|
||||
if (scheduledTasks.ContainsKey(scheduleInfo.ScheduleId) && !scheduledTasks[scheduleInfo.ScheduleId].Completed)
|
||||
{
|
||||
list.Add(scheduledTasks[scheduleInfo.ScheduleId]);
|
||||
}
|
||||
else
|
||||
{
|
||||
list.Add(new BackgroundTask
|
||||
{
|
||||
TaskId = "",
|
||||
ItemId = scheduleInfo.ScheduleId,
|
||||
StartDate = scheduleInfo.LastRun,
|
||||
TaskName = scheduleInfo.ScheduleName,
|
||||
UserId = SecurityContext.User.UserId,
|
||||
Source = "RUN_SCHEDULE",
|
||||
Severity = 0,
|
||||
ItemName = scheduleInfo.ScheduleName,
|
||||
Completed = false
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
|
@ -508,7 +550,7 @@ namespace WebsitePanel.EnterpriseServer
|
|||
string[] taskHandlers = GetTaskEventHandlers(task.Source, task.TaskName);
|
||||
if (taskHandlers != null)
|
||||
{
|
||||
foreach(string taskHandler in taskHandlers)
|
||||
foreach (string taskHandler in taskHandlers)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -650,8 +692,8 @@ namespace WebsitePanel.EnterpriseServer
|
|||
res.IsSuccess = true;
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,8 +13,9 @@
|
|||
<asp:TemplateField HeaderText="gvTasksName">
|
||||
<ItemStyle Width="40%"></ItemStyle>
|
||||
<ItemTemplate>
|
||||
<asp:hyperlink id="lnkTaskName" runat="server">
|
||||
<asp:hyperlink id="lnkTaskName" runat="server" Visible="false">
|
||||
</asp:hyperlink>
|
||||
<asp:Literal ID="litTaskName" runat="server" Visible="false"></asp:Literal>
|
||||
</ItemTemplate>
|
||||
</asp:TemplateField>
|
||||
<asp:BoundField DataField="ItemName" HeaderText="gvTasksItemName"></asp:BoundField>
|
||||
|
@ -26,15 +27,16 @@
|
|||
</asp:TemplateField>
|
||||
<asp:TemplateField HeaderText="gvTasksProgress">
|
||||
<ItemTemplate>
|
||||
<div class="ProgressBarContainer">
|
||||
<asp:Panel ID="pnlProgressBarContainer" runat="server" class="ProgressBarContainer" Visible="false">
|
||||
<asp:Panel id="pnlProgressIndicator" runat="server" CssClass="ProgressBarIndicator"></asp:Panel>
|
||||
</div>
|
||||
</asp:Panel>
|
||||
<asp:Literal ID="litProgressIndicator" runat="server" Visible="false">In Progress</asp:Literal>
|
||||
</ItemTemplate>
|
||||
</asp:TemplateField>
|
||||
<asp:TemplateField HeaderText="gvTasksActions">
|
||||
<ItemTemplate>
|
||||
<asp:LinkButton ID="cmdStop" runat="server" CommandName="stop"
|
||||
CausesValidation="false" Text="Stop" OnClientClick="return confirm('Do you really want to terminate this task?');"></asp:LinkButton>
|
||||
CausesValidation="false" Text="Stop" OnClientClick="return confirm('Do you really want to terminate this task?');" Visible="false"></asp:LinkButton>
|
||||
</ItemTemplate>
|
||||
</asp:TemplateField>
|
||||
</Columns>
|
||||
|
|
|
@ -66,13 +66,34 @@ namespace WebsitePanel.Portal
|
|||
|
||||
// find controls
|
||||
HyperLink lnkTaskName = (HyperLink)e.Row.FindControl("lnkTaskName");
|
||||
Literal litTaskName = (Literal)e.Row.FindControl("litTaskName");
|
||||
Literal litTaskDuration = (Literal)e.Row.FindControl("litTaskDuration");
|
||||
Panel pnlProgressBarContainer = (Panel)e.Row.FindControl("pnlProgressBarContainer");
|
||||
Panel pnlProgressIndicator = (Panel)e.Row.FindControl("pnlProgressIndicator");
|
||||
Literal litProgressIndicator = (Literal)e.Row.FindControl("litProgressIndicator");
|
||||
LinkButton cmdStop = (LinkButton)e.Row.FindControl("cmdStop");
|
||||
|
||||
// bind controls
|
||||
lnkTaskName.Text = GetAuditLogTaskName(task.Source, task.TaskName);
|
||||
lnkTaskName.NavigateUrl = EditUrl("TaskID", task.TaskId, "view_details");
|
||||
if (String.IsNullOrEmpty(task.TaskId))
|
||||
{
|
||||
litTaskName.Visible = true;
|
||||
litProgressIndicator.Visible = true;
|
||||
|
||||
// bind controls
|
||||
litTaskName.Text = GetAuditLogTaskName(task.Source, task.TaskName);
|
||||
}
|
||||
else
|
||||
{
|
||||
lnkTaskName.Visible = true;
|
||||
pnlProgressBarContainer.Visible = true;
|
||||
cmdStop.Visible = true;
|
||||
|
||||
// bind controls
|
||||
lnkTaskName.NavigateUrl = EditUrl("TaskID", task.TaskId, "view_details");
|
||||
lnkTaskName.Text = GetAuditLogTaskName(task.Source, task.TaskName);
|
||||
|
||||
// stop button
|
||||
cmdStop.CommandArgument = task.TaskId;
|
||||
}
|
||||
|
||||
// duration
|
||||
TimeSpan duration = (TimeSpan)(DateTime.Now - task.StartDate);
|
||||
|
@ -86,9 +107,6 @@ namespace WebsitePanel.Portal
|
|||
if (task.IndicatorMaximum > 0)
|
||||
percent = task.IndicatorCurrent * 100 / task.IndicatorMaximum;
|
||||
pnlProgressIndicator.Width = Unit.Percentage(percent);
|
||||
|
||||
// stop button
|
||||
cmdStop.CommandArgument = task.TaskId;
|
||||
}
|
||||
|
||||
protected void gvTasks_RowCommand(object sender, GridViewCommandEventArgs e)
|
||||
|
|
|
@ -1,19 +1,51 @@
|
|||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
// Runtime Version:2.0.50727.42
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace WebsitePanel.Portal {
|
||||
|
||||
|
||||
public partial class Tasks {
|
||||
protected System.Web.UI.Timer tasksTimer;
|
||||
protected System.Web.UI.UpdatePanel tasksUpdatePanel;
|
||||
protected System.Web.UI.WebControls.GridView gvTasks;
|
||||
protected System.Web.UI.WebControls.ObjectDataSource odsTasks;
|
||||
|
||||
/// <summary>
|
||||
/// tasksTimer control.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Auto-generated field.
|
||||
/// To modify move field declaration from designer file to code-behind file.
|
||||
/// </remarks>
|
||||
protected global::System.Web.UI.Timer tasksTimer;
|
||||
|
||||
/// <summary>
|
||||
/// tasksUpdatePanel control.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Auto-generated field.
|
||||
/// To modify move field declaration from designer file to code-behind file.
|
||||
/// </remarks>
|
||||
protected global::System.Web.UI.UpdatePanel tasksUpdatePanel;
|
||||
|
||||
/// <summary>
|
||||
/// gvTasks control.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Auto-generated field.
|
||||
/// To modify move field declaration from designer file to code-behind file.
|
||||
/// </remarks>
|
||||
protected global::System.Web.UI.WebControls.GridView gvTasks;
|
||||
|
||||
/// <summary>
|
||||
/// odsTasks control.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Auto-generated field.
|
||||
/// To modify move field declaration from designer file to code-behind file.
|
||||
/// </remarks>
|
||||
protected global::System.Web.UI.WebControls.ObjectDataSource odsTasks;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue