Skip to content

Commit

Permalink
Merge pull request #62 from JossyDevers/issue-dev-36
Browse files Browse the repository at this point in the history
Create a new status called Jobs Stopped
  • Loading branch information
bamotav authored Oct 23, 2020
2 parents 9162d85 + 72432e9 commit 658f671
Show file tree
Hide file tree
Showing 10 changed files with 205 additions and 14 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -340,3 +340,4 @@ ASALocalRun/

# BeatPulse healthcheck temp database
healthchecksdb
samples/Hangfire.Sample/HangfireSampleDb
Binary file modified samples/Hangfire.Sample/HangfireSampleDb
Binary file not shown.
10 changes: 9 additions & 1 deletion src/Hangfire.RecurringJobAdmin/ConfigurationExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,21 @@ public static IGlobalConfiguration UseRecurringJobAdmin(this IGlobalConfiguratio
private static void CreateManagmentJob()
{
DashboardRoutes.Routes.AddRazorPage(JobExtensionPage.PageRoute, x => new JobExtensionPage());
DashboardRoutes.Routes.AddRazorPage(JobsStoppedPage.PageRoute, x => new JobsStoppedPage());

DashboardRoutes.Routes.Add("/jobs/GetJobsStopped", new GetJobsStoppedDispatcher());
DashboardRoutes.Routes.Add("/JobConfiguration/GetJobs", new GetJobDispatcher());
DashboardRoutes.Routes.Add("/JobConfiguration/UpdateJobs", new ChangeJobDispatcher());
DashboardRoutes.Routes.Add("/JobConfiguration/GetJob", new GetJobForEdit());
DashboardRoutes.Routes.Add("/JobConfiguration/JobAgent", new JobAgentDispatcher());
DashboardRoutes.Routes.Add("/DataConfiguration/GetTimeZones", new GetTimeZonesDispatcher());


DashboardMetrics.AddMetric(TagDashboardMetrics.JobsStoppedCount);
JobsSidebarMenu.Items.Add(page => new MenuItem("Jobs Stopped", page.Url.To("/jobs/stopped"))
{
Active = page.RequestPath.StartsWith("/jobs/stopped"),
Metric = TagDashboardMetrics.JobsStoppedCount,
});

NavigationMenu.Items.Add(page => new MenuItem(JobExtensionPage.Title, page.Url.To("/JobConfiguration"))
{
Expand Down
92 changes: 92 additions & 0 deletions src/Hangfire.RecurringJobAdmin/Dashboard/JobsStopped.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<script type="text/javascript" src="../JobConfiguration/js/vue"></script>
<script type="text/javascript" src="../JobConfiguration/js/axio"></script>
<script type="text/javascript" src="../JobConfiguration/js/vuejsPaginate"></script>

<div id="app">
<div class="col-md-3"></div>
<div class="col-md-9">
<h1 class="page-header">Stopped Jobs</h1>

<div v-if="getItems.length == 0" class="alert alert-info">
No stopped jobs found
</div>
<div v-else class="js-jobs-list">
<div class="table-responsive">
<table class="table">

<thead>
<tr>
<th>Id</th>
<th>Queue</th>
<th>Class</th>
<th>Method</th>
<th>TimeZone</th>
</tr>
</thead>
<tbody>
<tr v-for="job in getItems">
<td>{{job.Id}}</td>
<td>{{job.Queue}}</td>
<td>{{job.Class}}</td>
<td>{{job.Method}}</td>
<td>{{job.TimeZoneId}}</td>
</tr>
</tbody>
</table>

<div style="float: right;">
<paginate :page-count="getPageCount"
:page-range="3"
:margin-pages="2"
:click-handler="clickCallbackPagination"
:prev-text="'<'"
:next-text="'>'"
:container-class="'pagination'"
:page-class="'page-item'">
</paginate>
</div>
</div>
</div>
</div>
</div>

<script>
var appJob = new Vue({
el: '#app',
components: {
'paginate': VuejsPaginate
},
data() {
return {
jobs: null,
pagination: {
parPage: 10,
currentPage: 1
}
}
},
methods: {
GetJobs() {
axios.get('GetJobsStopped')
.then(res => (this.jobs = res.data))
},
clickCallbackPagination(pageNum) {
this.pagination.currentPage = Number(pageNum);
}
},
created() {
this.GetJobs();
},
computed: {
getItems: function () {
let current = this.pagination.currentPage * this.pagination.parPage;
let start = current - this.pagination.parPage;
if (this.jobs != null) return this.jobs.slice(start, current);
else return null;
},
getPageCount: function () {
return Math.ceil(this.jobs.length / this.pagination.parPage);
}
}
});
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
<None Remove="Dashboard\Content\js\vue.js" />
<None Remove="Dashboard\Content\js\vuejs-paginate.js" />
<None Remove="Dashboard\JobExtension.html" />
<None Remove="Dashboard\JobsStopped.html" />
</ItemGroup>

<ItemGroup>
Expand Down Expand Up @@ -61,6 +62,7 @@
<EmbeddedResource Include="Dashboard\Content\js\vue.js">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</EmbeddedResource>
<EmbeddedResource Include="Dashboard\JobsStopped.html" />
<EmbeddedResource Include="Dashboard\JobExtension.html" />
</ItemGroup>

Expand Down
34 changes: 34 additions & 0 deletions src/Hangfire.RecurringJobAdmin/Pages/GetJobsStoppedDispatcher.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using Hangfire.Annotations;
using Hangfire.RecurringJobAdmin.Core;
using Hangfire.RecurringJobAdmin.Models;
using Hangfire.Storage;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Hangfire.RecurringJobAdmin.Pages
{
internal sealed class GetJobsStoppedDispatcher : Dashboard.IDashboardDispatcher
{
private readonly IStorageConnection _connection;
public GetJobsStoppedDispatcher()
{
_connection = JobStorage.Current.GetConnection();
}
public async Task Dispatch([NotNull] Dashboard.DashboardContext context)
{
if (!"GET".Equals(context.Request.Method, StringComparison.InvariantCultureIgnoreCase))
{
context.Response.StatusCode = 405;

return;
}

var periodicJob = new List<PeriodicJob>();
periodicJob.AddRange(JobAgent.GetAllJobStopped());

await context.Response.WriteAsync(JsonConvert.SerializeObject(periodicJob));
}
}
}
14 changes: 1 addition & 13 deletions src/Hangfire.RecurringJobAdmin/Pages/JobExtensionPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Hangfire.RecurringJobAdmin.Pages
{
internal sealed class JobExtensionPage : RazorPage
internal sealed class JobExtensionPage : PageBase
{
public const string Title = "Job Configuration";
public const string PageRoute = "/JobConfiguration";
Expand All @@ -26,17 +26,5 @@ public override void Execute()
WriteLiteralLine(PageHtml);
WriteEmptyLine();
}

private void WriteLiteralLine(string textToAppend)
{
WriteLiteral(textToAppend);
WriteLiteral("\r\n");
}

private void WriteEmptyLine()
{
WriteLiteral("\r\n");
}

}
}
28 changes: 28 additions & 0 deletions src/Hangfire.RecurringJobAdmin/Pages/JobsStoppedPage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Hangfire.Dashboard;
using Hangfire.Dashboard.Pages;
using Hangfire.RecurringJobAdmin.Core;

namespace Hangfire.RecurringJobAdmin.Pages
{
internal sealed class JobsStoppedPage : PageBase
{
public const string Title = "Stopped Jobs";
public const string PageRoute = "/jobs/stopped";

private static readonly string PageHtml;

static JobsStoppedPage()
{
PageHtml = Utility.ReadStringResource("Hangfire.RecurringJobAdmin.Dashboard.JobsStopped.html");
}

public override void Execute()
{
WriteEmptyLine();
Layout = new LayoutPage(Title);
Write(Html.JobsSidebar());
WriteLiteralLine(PageHtml);
WriteEmptyLine();
}
}
}
25 changes: 25 additions & 0 deletions src/Hangfire.RecurringJobAdmin/Pages/PageBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Hangfire.Dashboard;
using Hangfire.Dashboard.Pages;
using Hangfire.RecurringJobAdmin.Core;
using System;
using System.Collections.Generic;
using System.Text;

namespace Hangfire.RecurringJobAdmin.Pages
{
abstract internal class PageBase : RazorPage
{
public override void Execute() { }

protected void WriteLiteralLine(string textToAppend)
{
WriteLiteral(textToAppend);
WriteLiteral("\r\n");
}

protected void WriteEmptyLine()
{
WriteLiteral("\r\n");
}
}
}
13 changes: 13 additions & 0 deletions src/Hangfire.RecurringJobAdmin/TagDashboardMetrics.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Hangfire.Dashboard;
using Hangfire.RecurringJobAdmin.Core;

namespace Hangfire.RecurringJobAdmin
{
public static class TagDashboardMetrics
{
public static readonly DashboardMetric JobsStoppedCount = new DashboardMetric("JobsStopped:count", razorPage =>
{
return new Metric(JobAgent.GetAllJobStopped().Count);
});
}
}

0 comments on commit 658f671

Please sign in to comment.