Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable/Disable + Reschedule Recurring Jobs #2431

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Hangfire.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28307.136
# Visual Studio Version 17
VisualStudioVersion = 17.11.35208.52
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConsoleSample", "samples\ConsoleSample\ConsoleSample.csproj", "{C02BB718-2AE4-434C-8668-C894FF663FCE}"
EndProject
Expand All @@ -19,9 +19,9 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{15E186DF-8918-44F1-9285-9756EDAECA5D}"
ProjectSection(SolutionItems) = preProject
appveyor.yml = appveyor.yml
src\Directory.Build.props = src\Directory.Build.props
psake-project.ps1 = psake-project.ps1
src\SharedAssemblyInfo.cs = src\SharedAssemblyInfo.cs
src\Directory.Build.props = src\Directory.Build.props
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "nuspecs", "nuspecs", "{5E687025-A525-4534-8869-CB685C7B11C4}"
Expand Down Expand Up @@ -56,7 +56,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Hangfire.AspNetCore", "src\
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetCoreSample", "samples\NetCoreSample\NetCoreSample.csproj", "{FA751692-20C8-4986-8164-D21F505B2172}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Hangfire.NetCore", "src\Hangfire.NetCore\Hangfire.NetCore.csproj", "{AA8E3A67-8731-423A-9B69-EE44EC6B8E1A}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Hangfire.NetCore", "src\Hangfire.NetCore\Hangfire.NetCore.csproj", "{AA8E3A67-8731-423A-9B69-EE44EC6B8E1A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
11 changes: 11 additions & 0 deletions src/Hangfire.AspNetCore/Dashboard/AspNetCoreDashboardContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,16 @@ public override IRecurringJobManager GetRecurringJobManager()

return HttpContext.RequestServices.GetService<IRecurringJobManager>() ?? base.GetRecurringJobManager();
}

public override IRecurringJobManagerV2 GetRecurringJobManagerV2()
{
var factory = HttpContext.RequestServices.GetService<IRecurringJobManagerFactoryV2>();
if (factory != null)
{
return factory.GetManagerV2(Storage);
}

return HttpContext.RequestServices.GetService<IRecurringJobManagerV2>() ?? base.GetRecurringJobManagerV2();
}
}
}
63 changes: 63 additions & 0 deletions src/Hangfire.Core/Dashboard/Content/resx/Strings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions src/Hangfire.Core/Dashboard/Content/resx/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -578,4 +578,25 @@
<data name="Metrics_SQLServer_LogFilesSize" xml:space="preserve">
<value>Log File(s) Used (MB)</value>
</data>
<data name="Common_Disable" xml:space="preserve">
<value>Disable</value>
</data>
<data name="Common_Enable" xml:space="preserve">
<value>Enable</value>
</data>
<data name="Common_Enabled" xml:space="preserve">
<value>Enabled</value>
</data>
<data name="Common_Disabling" xml:space="preserve">
<value>Disabling...</value>
</data>
<data name="Common_Enabling" xml:space="preserve">
<value>Enabling...</value>
</data>
<data name="Common_DisableConfirm" xml:space="preserve">
<value>Do you really want to DISABLE ALL selected jobs?</value>
</data>
<data name="Common_EnableConfirm" xml:space="preserve">
<value>Do you really want to ENABLE ALL selected jobs?</value>
</data>
</root>
5 changes: 5 additions & 0 deletions src/Hangfire.Core/Dashboard/DashboardContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,10 @@ public virtual IRecurringJobManager GetRecurringJobManager()
JobFilterProviders.Providers,
Options.TimeZoneResolver ?? new DefaultTimeZoneResolver());
}

public virtual IRecurringJobManagerV2 GetRecurringJobManagerV2()
{
return (IRecurringJobManagerV2)GetRecurringJobManager();
}
}
}
8 changes: 8 additions & 0 deletions src/Hangfire.Core/Dashboard/DashboardRoutes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,14 @@ static DashboardRoutes()
Routes.AddRecurringBatchCommand(
"/recurring/trigger",
static (manager, jobId) => manager.Trigger(jobId));

Routes.AddRecurringBatchCommandV2(
"/recurring/disable",
static (manager, jobId) => manager.DisableIfExists(jobId));

Routes.AddRecurringBatchCommandV2(
"/recurring/enable",
static (manager, jobId) => manager.EnableIfExists(jobId));

Routes.AddRazorPage("/servers", static _ => new ServersPage());
Routes.AddRazorPage("/retries", static _ => new RetriesPage());
Expand Down
26 changes: 24 additions & 2 deletions src/Hangfire.Core/Dashboard/Pages/RecurringJobsPage.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,28 @@
@Strings.Common_Delete
</button>
}
@if (!IsReadOnly)
{
<button class="js-jobs-list-command btn btn-sm btn-default"
data-url="@Url.To("/recurring/disable")"
data-loading-text="@Strings.Common_Disabling"
data-confirm="@Strings.Common_DisableConfirm"
disabled="disabled">
<span class="glyphicon glyphicon-stop"></span>
@Strings.Common_Disable
</button>
}
@if (!IsReadOnly)
{
<button class="js-jobs-list-command btn btn-sm btn-default"
data-url="@Url.To("/recurring/enable")"
data-loading-text="@Strings.Common_Enabling"
data-confirm="@Strings.Common_EnableConfirm"
disabled="disabled">
<span class="glyphicon glyphicon-play"></span>
@Strings.Common_Enable
</button>
}
@if (pager != null)
{
@: @Html.PerPageSelector(pager)
Expand Down Expand Up @@ -116,7 +138,7 @@
{
RecurringJobEntity.ParseCronExpression(job.Cron);
}
catch (Exception ex) when (ex.IsCatchableExceptionType())
catch (Exception ex)
{
cronDescription = ex.Message;
cronError = true;
Expand Down Expand Up @@ -163,7 +185,7 @@
var resolver = DashboardOptions.TimeZoneResolver ?? new DefaultTimeZoneResolver();
displayName = resolver.GetTimeZoneById(job.TimeZoneId).DisplayName;
}
catch (Exception ex) when (ex.IsCatchableExceptionType())
catch (Exception ex)
{
displayName = null;
exception = ex;
Expand Down
Loading