Last active
April 11, 2016 20:38
-
-
Save lowedown/7b6b4828de2204362edf to your computer and use it in GitHub Desktop.
Sitecore Admin Page to show currently running Jobs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%@ Page Language="C#" AutoEventWireup="true" %> | |
<%@ Import Namespace="Sitecore.Jobs" %> | |
<!DOCTYPE html> | |
<html xmlns="http://www.w3.org/1999/xhtml"> | |
<head id="Head1" runat="server"> | |
<title>Running Sitecore Background Jobs</title> | |
<meta http-equiv="refresh" content="3" /> | |
</head> | |
<body> | |
<form id="form1" runat="server"> | |
<div> | |
<h1>Running Sitecore Background Jobs</h1> | |
<table> | |
<tr> | |
<th>Name</th> | |
<th>Category</th> | |
<th>State</th> | |
<th>Is Done</th> | |
<th>Queue Time (local time)</th> | |
<th>Processed</th> | |
<th>Last Message</th> | |
</tr> | |
<asp:Repeater runat="server" ID="repContent" ItemType="Sitecore.Jobs.Job"> | |
<ItemTemplate> | |
<tr class="<%# Container.ItemIndex % 2 == 0 ? "" : "alternate" %>"> | |
<td><%# Item.Name %></td> | |
<td><%# Item.Category %></td> | |
<td><%# Item.Status.State %></td> | |
<td><%# Item.IsDone %></td> | |
<td><%# Item.QueueTime %></td> | |
<td><%# (Item.Status != null) ? Item.Status.Processed : 0 %> <%# (Item.Status != null && Item.Status.Total > 1) ? ((Item.Status.Processed * 100) / Item.Status.Total).ToString("(#.#") + "%)" : string.Empty %></td> | |
<td><%# (Item.Status != null && Item.Status.Messages.Count > 0) ? Item.Status.Messages[Item.Status.Messages.Count - 1] : string.Empty %></td> | |
</tr> | |
</ItemTemplate> | |
</asp:Repeater> | |
</table> | |
</div> | |
<script runat="server"> | |
protected override void OnInit(EventArgs arguments) | |
{ | |
CheckSecurity(true); | |
} | |
protected void CheckSecurity(bool isDeveloperAllowed) | |
{ | |
if (Sitecore.Context.User.IsAdministrator || (isDeveloperAllowed && this.IsDeveloper)) return; | |
var site = Sitecore.Context.Site; | |
if (site != null) | |
{ | |
base.Response.Redirect(string.Format("{0}?returnUrl={1}", site.LoginPage, HttpUtility.UrlEncode(base.Request.Url.PathAndQuery))); | |
} | |
} | |
private bool IsDeveloper | |
{ | |
get | |
{ | |
return User.IsInRole(@"sitecore\developer") || User.IsInRole(@"sitecore\sitecore client developing"); | |
} | |
} | |
protected void Page_Load(object sender, EventArgs e) | |
{ | |
var jobs = JobManager.GetJobs(); | |
repContent.DataSource = jobs; | |
repContent.DataBind(); | |
} | |
</script> | |
</form> | |
</body> | |
</html> |
Update: Added the "Last Message" column and Percentage if a total is known.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Simple unstyled admin page that will show you all the jobs currently running and ones that have finished shortly ago. The page will refresh every 3 seconds.