Feature #37: Stale Jobs

Stale Jobs replaces Long-Running Jobs on the homepage. Last Activity is
added to the job table.
This commit is contained in:
Gary Sharp
2014-02-13 22:17:49 +11:00
parent 2ac3a9bdd3
commit 68256d7abd
30 changed files with 881 additions and 330 deletions
@@ -10,8 +10,6 @@ namespace Disco.Web.Areas.API.Controllers
{
public partial class JobPreferencesController : AuthorizedDatabaseController
{
const string pLongRunningJobDaysThreshold = "longrunningjobdaysthreshold";
[DiscoAuthorize(Claims.Config.JobPreferences.Configure)]
public virtual ActionResult UpdateLongRunningJobDaysThreshold(int LongRunningJobDaysThreshold, bool redirect = false)
{
@@ -24,5 +22,16 @@ namespace Disco.Web.Areas.API.Controllers
return Json("OK", JsonRequestBehavior.AllowGet);
}
[DiscoAuthorize(Claims.Config.JobPreferences.Configure)]
public virtual ActionResult UpdateStaleJobMinutesThreshold(int StaleJobMinutesThreshold, bool redirect = false)
{
Database.DiscoConfiguration.JobPreferences.StaleJobMinutesThreshold = StaleJobMinutesThreshold;
Database.SaveChanges();
if (redirect)
return RedirectToAction(MVC.Config.JobPreferences.Index());
else
return Json("OK", JsonRequestBehavior.AllowGet);
}
}
}
@@ -17,7 +17,8 @@ namespace Disco.Web.Areas.Config.Controllers
{
var m = new Models.JobPreferences.IndexModel()
{
LongRunningJobDaysThreshold = Database.DiscoConfiguration.JobPreferences.LongRunningJobDaysThreshold
LongRunningJobDaysThreshold = Database.DiscoConfiguration.JobPreferences.LongRunningJobDaysThreshold,
StaleJobMinutesThreshold = Database.DiscoConfiguration.JobPreferences.StaleJobMinutesThreshold
};
// UI Extensions
@@ -10,6 +10,7 @@ namespace Disco.Web.Areas.Config.Models.JobPreferences
public class IndexModel : ConfigJobPreferencesIndexModel
{
public int LongRunningJobDaysThreshold { get; set; }
public int StaleJobMinutesThreshold { get; set; }
public List<KeyValuePair<int, string>> LongRunningJobDaysThresholdOptions()
{
@@ -39,5 +40,41 @@ namespace Disco.Web.Areas.Config.Models.JobPreferences
return options;
}
public List<KeyValuePair<int, string>> StaleJobMinutesThresholdOptions()
{
var options = new List<KeyValuePair<int, string>>() {
new KeyValuePair<int, string>(0, "<None>"),
new KeyValuePair<int, string>(15, "15 minutes"),
new KeyValuePair<int, string>(30, "30 minutes"),
new KeyValuePair<int, string>(60, "1 hour"),
new KeyValuePair<int, string>(60 * 2, "2 hours"),
new KeyValuePair<int, string>(60 * 4, "4 hours"),
new KeyValuePair<int, string>(60 * 8, "8 hours"),
new KeyValuePair<int, string>(60 * 24, "1 day"),
new KeyValuePair<int, string>(60 * 24 * 2, "2 days"),
new KeyValuePair<int, string>(60 * 24 * 3, "3 days"),
new KeyValuePair<int, string>(60 * 24 * 4, "4 days"),
new KeyValuePair<int, string>(60 * 24 * 5, "5 days"),
new KeyValuePair<int, string>(60 * 24 * 6, "6 days"),
new KeyValuePair<int, string>(60 * 24 * 7, "1 week"),
new KeyValuePair<int, string>(60 * 24 * 7 * 2, "2 weeks"),
new KeyValuePair<int, string>(60 * 24 * 7 * 3, "3 weeks"),
new KeyValuePair<int, string>(60 * 24 * 7 * 4, "4 weeks"),
new KeyValuePair<int, string>(60 * 24 * 7 * 5, "5 weeks"),
new KeyValuePair<int, string>(60 * 24 * 7 * 6, "6 weeks"),
new KeyValuePair<int, string>(60 * 24 * 7 * 7, "7 weeks"),
new KeyValuePair<int, string>(60 * 24 * 7 * 8, "8 weeks")
};
var current = this.StaleJobMinutesThreshold;
if (!options.Any(o => o.Key == current))
{
options.Add(new KeyValuePair<int, string>(current, string.Format("{0} Minutes", current)));
options = options.OrderBy(o => o.Key).ToList();
}
return options;
}
}
}
@@ -40,6 +40,35 @@
<div class="smallMessage">
Jobs which have been open for longer than the threshold are considered 'long-running' and will appear in the <code>Long Running Jobs</code> list.
</div>
@if (Authorization.Has(Claims.Job.Lists.LongRunningJobs)) { @Html.ActionLinkSmallButton("Show Long Running Jobs", MVC.Job.LongRunning()) }
</td>
</tr>
<tr>
<th style="width: 200px">Stale Threshold:
</th>
<td>@if (canConfig)
{
@Html.DropDownListFor(model => model.StaleJobMinutesThreshold, Model.StaleJobMinutesThresholdOptions().Select(o => new SelectListItem() { Value = o.Key.ToString(), Text = o.Value }))
@AjaxHelpers.AjaxSave()
@AjaxHelpers.AjaxLoader()
<script type="text/javascript">
$(function () {
document.DiscoFunctions.PropertyChangeHelper(
$('#StaleJobMinutesThreshold'),
null,
'@(Url.Action(MVC.API.JobPreferences.UpdateStaleJobMinutesThreshold()))',
'StaleJobMinutesThreshold');
});
</script>
}
else
{
@Model.StaleJobMinutesThresholdOptions().First(o => o.Key == Model.StaleJobMinutesThreshold).Value
}
<div class="smallMessage">
Jobs which have no recoded action for longer than the threshold are considered 'stale' and will appear in the <code>Stale Jobs</code> list.
</div>
@if (Authorization.Has(Claims.Job.Lists.LongRunningJobs)) { @Html.ActionLinkSmallButton("Show Stale Jobs", MVC.Job.Stale()) }
</td>
</tr>
</table>
@@ -29,6 +29,7 @@ namespace Disco.Web.Areas.Config.Views.JobPreferences
using Disco;
using Disco.BI.Extensions;
using Disco.Models.Repository;
using Disco.Services;
using Disco.Services.Authorization;
using Disco.Services.Web;
using Disco.Web;
@@ -171,8 +172,167 @@ WriteLiteral(" class=\"smallMessage\"");
WriteLiteral(">\r\n Jobs which have been open for longer than the threshold ar" +
"e considered \'long-running\' and will appear in the <code>Long Running Jobs</code" +
"> list.\r\n </div>\r\n </td>\r\n </tr>\r\n </table>\r" +
"\n</div>\r\n");
"> list.\r\n </div>\r\n");
#line 43 "..\..\Areas\Config\Views\JobPreferences\Index.cshtml"
#line default
#line hidden
#line 43 "..\..\Areas\Config\Views\JobPreferences\Index.cshtml"
if (Authorization.Has(Claims.Job.Lists.LongRunningJobs)) {
#line default
#line hidden
#line 43 "..\..\Areas\Config\Views\JobPreferences\Index.cshtml"
Write(Html.ActionLinkSmallButton("Show Long Running Jobs", MVC.Job.LongRunning()));
#line default
#line hidden
#line 43 "..\..\Areas\Config\Views\JobPreferences\Index.cshtml"
}
#line default
#line hidden
WriteLiteral(" </td>\r\n </tr>\r\n <tr>\r\n <th");
WriteLiteral(" style=\"width: 200px\"");
WriteLiteral(">Stale Threshold:\r\n </th>\r\n <td>");
#line 49 "..\..\Areas\Config\Views\JobPreferences\Index.cshtml"
if (canConfig)
{
#line default
#line hidden
#line 51 "..\..\Areas\Config\Views\JobPreferences\Index.cshtml"
Write(Html.DropDownListFor(model => model.StaleJobMinutesThreshold, Model.StaleJobMinutesThresholdOptions().Select(o => new SelectListItem() { Value = o.Key.ToString(), Text = o.Value })));
#line default
#line hidden
#line 51 "..\..\Areas\Config\Views\JobPreferences\Index.cshtml"
#line default
#line hidden
#line 52 "..\..\Areas\Config\Views\JobPreferences\Index.cshtml"
Write(AjaxHelpers.AjaxSave());
#line default
#line hidden
#line 52 "..\..\Areas\Config\Views\JobPreferences\Index.cshtml"
#line default
#line hidden
#line 53 "..\..\Areas\Config\Views\JobPreferences\Index.cshtml"
Write(AjaxHelpers.AjaxLoader());
#line default
#line hidden
#line 53 "..\..\Areas\Config\Views\JobPreferences\Index.cshtml"
#line default
#line hidden
WriteLiteral(" <script");
WriteLiteral(" type=\"text/javascript\"");
WriteLiteral(">\r\n $(function () {\r\n document.DiscoFun" +
"ctions.PropertyChangeHelper(\r\n $(\'#StaleJobMinutesThr" +
"eshold\'),\r\n null,\r\n \'");
#line 59 "..\..\Areas\Config\Views\JobPreferences\Index.cshtml"
Write(Url.Action(MVC.API.JobPreferences.UpdateStaleJobMinutesThreshold()));
#line default
#line hidden
WriteLiteral("\',\r\n \'StaleJobMinutesThreshold\');\r\n " +
" });\r\n </script>\r\n");
#line 63 "..\..\Areas\Config\Views\JobPreferences\Index.cshtml"
}
else
{
#line default
#line hidden
#line 66 "..\..\Areas\Config\Views\JobPreferences\Index.cshtml"
Write(Model.StaleJobMinutesThresholdOptions().First(o => o.Key == Model.StaleJobMinutesThreshold).Value);
#line default
#line hidden
#line 66 "..\..\Areas\Config\Views\JobPreferences\Index.cshtml"
}
#line default
#line hidden
WriteLiteral(" <div");
WriteLiteral(" class=\"smallMessage\"");
WriteLiteral(">\r\n Jobs which have no recoded action for longer than the thre" +
"shold are considered \'stale\' and will appear in the <code>Stale Jobs</code> list" +
".\r\n </div>\r\n");
#line 71 "..\..\Areas\Config\Views\JobPreferences\Index.cshtml"
#line default
#line hidden
#line 71 "..\..\Areas\Config\Views\JobPreferences\Index.cshtml"
if (Authorization.Has(Claims.Job.Lists.LongRunningJobs)) {
#line default
#line hidden
#line 71 "..\..\Areas\Config\Views\JobPreferences\Index.cshtml"
Write(Html.ActionLinkSmallButton("Show Stale Jobs", MVC.Job.Stale()));
#line default
#line hidden
#line 71 "..\..\Areas\Config\Views\JobPreferences\Index.cshtml"
}
#line default
#line hidden
WriteLiteral(" </td>\r\n </tr>\r\n </table>\r\n</div>\r\n");
}
}