Items { get; }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/Hangfire.Core/Dashboard/Pages/_Breadcrumbs.cshtml:
--------------------------------------------------------------------------------
1 | @* Generator: Template TypeVisibility: Internal GeneratePrettyNames: True TrimLeadingUnderscores : true *@
2 | @using Hangfire.Dashboard
3 | @inherits RazorPage
4 |
5 |
6 |
7 | @foreach (var item in Items)
8 | {
9 | - @item.Key
10 | }
11 | - @Title
12 |
--------------------------------------------------------------------------------
/src/Hangfire.Core/Dashboard/Pages/_ErrorAlert.cshtml:
--------------------------------------------------------------------------------
1 | @* Generator: Template TypeVisibility: Internal GeneratePrettyNames: True TrimLeadingUnderscores : true *@
2 | @using Hangfire.Dashboard
3 | @inherits RazorPage
4 |
5 |
--------------------------------------------------------------------------------
/src/Hangfire.Core/Dashboard/Pages/_ErrorAlert.cshtml.cs:
--------------------------------------------------------------------------------
1 | #pragma warning disable 1591
2 | //------------------------------------------------------------------------------
3 | //
4 | // This code was generated by a tool.
5 | // Runtime Version:4.0.30319.42000
6 | //
7 | // Changes to this file may cause incorrect behavior and will be lost if
8 | // the code is regenerated.
9 | //
10 | //------------------------------------------------------------------------------
11 |
12 | namespace Hangfire.Dashboard.Pages
13 | {
14 | using System;
15 | using System.Collections.Generic;
16 | using System.Linq;
17 | using System.Text;
18 |
19 | #line 2 "..\..\Dashboard\Pages\_ErrorAlert.cshtml"
20 | using Hangfire.Dashboard;
21 |
22 | #line default
23 | #line hidden
24 |
25 | [System.CodeDom.Compiler.GeneratedCodeAttribute("RazorGenerator", "2.0.0.0")]
26 | internal partial class ErrorAlert : RazorPage
27 | {
28 | #line hidden
29 |
30 | public override void Execute()
31 | {
32 |
33 |
34 | WriteLiteral("\r\n");
35 |
36 |
37 |
38 | WriteLiteral("\r\n");
41 |
42 |
43 | }
44 | }
45 | }
46 | #pragma warning restore 1591
47 |
--------------------------------------------------------------------------------
/src/Hangfire.Core/Dashboard/Pages/_InlineMetric.cs:
--------------------------------------------------------------------------------
1 | namespace Hangfire.Dashboard.Pages
2 | {
3 | partial class InlineMetric
4 | {
5 | public InlineMetric(DashboardMetric dashboardMetric)
6 | {
7 | DashboardMetric = dashboardMetric;
8 | }
9 |
10 | public DashboardMetric DashboardMetric { get; }
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/src/Hangfire.Core/Dashboard/Pages/_InlineMetric.cshtml:
--------------------------------------------------------------------------------
1 | @* Generator: Template TypeVisibility: Internal GeneratePrettyNames: True TrimLeadingUnderscores : true *@
2 | @using Hangfire.Dashboard
3 | @inherits RazorPage
4 | @{
5 | var metric = DashboardMetric.Func(this);
6 | var className = metric == null ? "metric-null" : metric.Style.ToClassName();
7 | var highlighted = metric != null && metric.Highlighted ? "highlighted" : null;
8 | }
9 | @(metric?.Value)
--------------------------------------------------------------------------------
/src/Hangfire.Core/Dashboard/Pages/_Navigation.cshtml:
--------------------------------------------------------------------------------
1 | @* Generator: Template TypeVisibility: Internal GeneratePrettyNames: True TrimLeadingUnderscores : true *@
2 | @using Hangfire.Dashboard
3 | @inherits RazorPage
4 | @if (NavigationMenu.Items.Count > 0)
5 | {
6 |
25 | }
--------------------------------------------------------------------------------
/src/Hangfire.Core/Dashboard/Pages/_Paginator.cs:
--------------------------------------------------------------------------------
1 | namespace Hangfire.Dashboard.Pages
2 | {
3 | partial class Paginator
4 | {
5 | private readonly Pager _pager;
6 |
7 | public Paginator(Pager pager)
8 | {
9 | _pager = pager;
10 | }
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/src/Hangfire.Core/Dashboard/Pages/_PerPageSelector.cs:
--------------------------------------------------------------------------------
1 | namespace Hangfire.Dashboard.Pages
2 | {
3 | partial class PerPageSelector
4 | {
5 | private readonly Pager _pager;
6 |
7 | public PerPageSelector(Pager pager)
8 | {
9 | _pager = pager;
10 | }
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/src/Hangfire.Core/Dashboard/Pages/_PerPageSelector.cshtml:
--------------------------------------------------------------------------------
1 | @* Generator: Template TypeVisibility: Internal GeneratePrettyNames: True TrimLeadingUnderscores : true *@
2 | @using Hangfire.Dashboard.Resources;
3 | @inherits Hangfire.Dashboard.RazorPage
4 |
5 | @if (_pager.TotalPageCount > 1)
6 | {
7 |
8 |
11 |
14 |
15 | }
16 |
17 | @foreach (var count in new[] { 10, 20, 50, 100, 500, 1000, 5000 })
18 | {
19 |
21 | }
22 |
23 |
24 |
25 | @Strings.PerPageSelector_ItemsPerPage:
26 |
27 |
--------------------------------------------------------------------------------
/src/Hangfire.Core/Dashboard/Pages/_SidebarMenu.cs:
--------------------------------------------------------------------------------
1 | // This file is part of Hangfire. Copyright © 2015 Hangfire OÜ.
2 | //
3 | // Hangfire is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Lesser General Public License as
5 | // published by the Free Software Foundation, either version 3
6 | // of the License, or any later version.
7 | //
8 | // Hangfire is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU Lesser General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU Lesser General Public
14 | // License along with Hangfire. If not, see .
15 |
16 | using System;
17 | using System.Collections.Generic;
18 | using Hangfire.Annotations;
19 |
20 | namespace Hangfire.Dashboard.Pages
21 | {
22 | partial class SidebarMenu
23 | {
24 | public SidebarMenu([NotNull] IEnumerable> items)
25 | {
26 | if (items == null) throw new ArgumentNullException(nameof(items));
27 | Items = items;
28 | }
29 |
30 | public IEnumerable> Items { get; }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/Hangfire.Core/Dashboard/Pages/_SidebarMenu.cshtml:
--------------------------------------------------------------------------------
1 | @* Generator: Template TypeVisibility: Internal GeneratePrettyNames: True TrimLeadingUnderscores : true *@
2 | @using Hangfire.Dashboard
3 | @inherits RazorPage
4 | @if (Items.Any())
5 | {
6 |
21 | }
22 |
--------------------------------------------------------------------------------
/src/Hangfire.Core/Dashboard/RazorPageDispatcher.cs:
--------------------------------------------------------------------------------
1 | // This file is part of Hangfire. Copyright © 2013-2014 Hangfire OÜ.
2 | //
3 | // Hangfire is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Lesser General Public License as
5 | // published by the Free Software Foundation, either version 3
6 | // of the License, or any later version.
7 | //
8 | // Hangfire is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU Lesser General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU Lesser General Public
14 | // License along with Hangfire. If not, see .
15 |
16 | using System;
17 | using System.Text.RegularExpressions;
18 | using System.Threading.Tasks;
19 |
20 | namespace Hangfire.Dashboard
21 | {
22 | internal sealed class RazorPageDispatcher : IDashboardDispatcher
23 | {
24 | private readonly Func _pageFunc;
25 |
26 | public RazorPageDispatcher(Func pageFunc)
27 | {
28 | _pageFunc = pageFunc;
29 | }
30 |
31 | public Task Dispatch(DashboardContext context)
32 | {
33 | context.Response.ContentType = "text/html";
34 |
35 | var page = _pageFunc(context.UriMatch);
36 | page.Assign(context);
37 |
38 | return context.Response.WriteAsync(page.ToString());
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/Hangfire.Core/ExceptionTypeHelper.cs:
--------------------------------------------------------------------------------
1 | // This file is part of Hangfire. Copyright © 2022 Hangfire OÜ.
2 | //
3 | // Hangfire is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Lesser General Public License as
5 | // published by the Free Software Foundation, either version 3
6 | // of the License, or any later version.
7 | //
8 | // Hangfire is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU Lesser General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU Lesser General Public
14 | // License along with Hangfire. If not, see .
15 |
16 | using System;
17 |
18 | namespace Hangfire
19 | {
20 | internal static class ExceptionTypeHelper
21 | {
22 | #if !NETSTANDARD1_3
23 | private static readonly Type StackOverflowType = typeof(StackOverflowException);
24 | #endif
25 | private static readonly Type OutOfMemoryType = typeof(OutOfMemoryException);
26 |
27 | internal static bool IsCatchableExceptionType(this Exception e)
28 | {
29 | var type = e.GetType();
30 | return
31 | #if !NETSTANDARD1_3
32 | type != StackOverflowType &&
33 | #endif
34 | type != OutOfMemoryType;
35 | }
36 | }
37 | }
--------------------------------------------------------------------------------
/src/Hangfire.Core/FromParameterAttribute.cs:
--------------------------------------------------------------------------------
1 | // This file is part of Hangfire. Copyright © 2019 Hangfire OÜ.
2 | //
3 | // Hangfire is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Lesser General Public License as
5 | // published by the Free Software Foundation, either version 3
6 | // of the License, or any later version.
7 | //
8 | // Hangfire is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU Lesser General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU Lesser General Public
14 | // License along with Hangfire. If not, see .
15 |
16 | using System;
17 |
18 | namespace Hangfire
19 | {
20 | [AttributeUsage(AttributeTargets.Parameter)]
21 | public class FromParameterAttribute : Attribute
22 | {
23 | public FromParameterAttribute(string parameterName)
24 | {
25 | ParameterName = parameterName;
26 | }
27 |
28 | public string ParameterName { get; }
29 | }
30 | }
--------------------------------------------------------------------------------
/src/Hangfire.Core/FromResultAttribute.cs:
--------------------------------------------------------------------------------
1 | // This file is part of Hangfire. Copyright © 2019 Hangfire OÜ.
2 | //
3 | // Hangfire is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Lesser General Public License as
5 | // published by the Free Software Foundation, either version 3
6 | // of the License, or any later version.
7 | //
8 | // Hangfire is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU Lesser General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU Lesser General Public
14 | // License along with Hangfire. If not, see .
15 |
16 | using System;
17 |
18 | namespace Hangfire
19 | {
20 | [AttributeUsage(AttributeTargets.Parameter)]
21 | public sealed class FromResultAttribute : FromParameterAttribute
22 | {
23 | public FromResultAttribute() : base("AntecedentResult")
24 | {
25 | }
26 | }
27 |
28 | [AttributeUsage(AttributeTargets.Parameter)]
29 | public sealed class FromExceptionAttribute : FromParameterAttribute
30 | {
31 | public FromExceptionAttribute() : base("AntecedentException")
32 | {
33 | }
34 | }
35 | }
--------------------------------------------------------------------------------
/src/Hangfire.Core/GlobalStateHandlers.cs:
--------------------------------------------------------------------------------
1 | // This file is part of Hangfire. Copyright © 2013-2014 Hangfire OÜ.
2 | //
3 | // Hangfire is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Lesser General Public License as
5 | // published by the Free Software Foundation, either version 3
6 | // of the License, or any later version.
7 | //
8 | // Hangfire is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU Lesser General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU Lesser General Public
14 | // License along with Hangfire. If not, see .
15 |
16 | using System.Collections.Generic;
17 | using Hangfire.States;
18 |
19 | namespace Hangfire
20 | {
21 | public static class GlobalStateHandlers
22 | {
23 | static GlobalStateHandlers()
24 | {
25 | Handlers = new List
26 | {
27 | new SucceededState.Handler(),
28 | new ScheduledState.Handler(),
29 | new EnqueuedState.Handler(),
30 | new DeletedState.Handler(),
31 | new AwaitingState.Handler()
32 | };
33 | }
34 |
35 | public static ICollection Handlers { get; }
36 | }
37 | }
--------------------------------------------------------------------------------
/src/Hangfire.Core/IGlobalConfiguration.cs:
--------------------------------------------------------------------------------
1 | // This file is part of Hangfire. Copyright © 2015 Hangfire OÜ.
2 | //
3 | // Hangfire is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Lesser General Public License as
5 | // published by the Free Software Foundation, either version 3
6 | // of the License, or any later version.
7 | //
8 | // Hangfire is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU Lesser General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU Lesser General Public
14 | // License along with Hangfire. If not, see .
15 |
16 | using System.ComponentModel;
17 |
18 | namespace Hangfire
19 | {
20 | [EditorBrowsable(EditorBrowsableState.Never)]
21 | public interface IGlobalConfiguration : IGlobalConfiguration
22 | {
23 | [EditorBrowsable(EditorBrowsableState.Advanced)]
24 | T Entry { get; }
25 | }
26 |
27 | [EditorBrowsable(EditorBrowsableState.Never)]
28 | public interface IGlobalConfiguration
29 | {
30 | }
31 | }
--------------------------------------------------------------------------------
/src/Hangfire.Core/IJobCancellationToken.cs:
--------------------------------------------------------------------------------
1 | // This file is part of Hangfire. Copyright © 2013-2014 Hangfire OÜ.
2 | //
3 | // Hangfire is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Lesser General Public License as
5 | // published by the Free Software Foundation, either version 3
6 | // of the License, or any later version.
7 | //
8 | // Hangfire is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU Lesser General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU Lesser General Public
14 | // License along with Hangfire. If not, see .
15 |
16 | using System.Threading;
17 |
18 | namespace Hangfire
19 | {
20 | public interface IJobCancellationToken
21 | {
22 | CancellationToken ShutdownToken { get; }
23 |
24 | ///
25 | /// Throws a OperationCanceledException if
26 | /// this token has had cancellation requested.
27 | ///
28 | ///
29 | /// This method provides functionality equivalent to:
30 | ///
31 | /// if (token.ShutdownToken.IsCancellationRequested)
32 | /// throw new OperationCanceledException(token);
33 | ///
34 | ///
35 | /// The token has had cancellation requested.
36 | void ThrowIfCancellationRequested();
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/Hangfire.Core/IRecurringJobManager.cs:
--------------------------------------------------------------------------------
1 | // This file is part of Hangfire. Copyright © 2016 Hangfire OÜ.
2 | //
3 | // Hangfire is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Lesser General Public License as
5 | // published by the Free Software Foundation, either version 3
6 | // of the License, or any later version.
7 | //
8 | // Hangfire is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU Lesser General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU Lesser General Public
14 | // License along with Hangfire. If not, see .
15 |
16 | using Hangfire.Annotations;
17 | using Hangfire.Common;
18 |
19 | namespace Hangfire
20 | {
21 | public interface IRecurringJobManagerV2 : IRecurringJobManager
22 | {
23 | [NotNull]
24 | JobStorage Storage { get; }
25 |
26 | [CanBeNull]
27 | string TriggerJob([NotNull] string recurringJobId);
28 | }
29 |
30 | public interface IRecurringJobManager
31 | {
32 | void AddOrUpdate(
33 | [NotNull] string recurringJobId,
34 | [NotNull] Job job,
35 | [NotNull] string cronExpression,
36 | [NotNull] RecurringJobOptions options);
37 |
38 | void Trigger([NotNull] string recurringJobId);
39 | void RemoveIfExists([NotNull] string recurringJobId);
40 | }
41 | }
--------------------------------------------------------------------------------
/src/Hangfire.Core/ITimeZoneResolver.cs:
--------------------------------------------------------------------------------
1 | // This file is part of Hangfire. Copyright © 2019 Hangfire OÜ.
2 | //
3 | // Hangfire is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Lesser General Public License as
5 | // published by the Free Software Foundation, either version 3
6 | // of the License, or any later version.
7 | //
8 | // Hangfire is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU Lesser General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU Lesser General Public
14 | // License along with Hangfire. If not, see .
15 |
16 | using System;
17 | using Hangfire.Annotations;
18 |
19 | namespace Hangfire
20 | {
21 | public sealed class DefaultTimeZoneResolver : ITimeZoneResolver
22 | {
23 | public TimeZoneInfo GetTimeZoneById(string timeZoneId)
24 | {
25 | return TimeZoneInfo.FindSystemTimeZoneById(timeZoneId);
26 | }
27 | }
28 |
29 | public interface ITimeZoneResolver
30 | {
31 | [NotNull]
32 | TimeZoneInfo GetTimeZoneById([NotNull] string timeZoneId);
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/Hangfire.Core/JobCancellationToken.cs:
--------------------------------------------------------------------------------
1 | // This file is part of Hangfire. Copyright © 2013-2014 Hangfire OÜ.
2 | //
3 | // Hangfire is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Lesser General Public License as
5 | // published by the Free Software Foundation, either version 3
6 | // of the License, or any later version.
7 | //
8 | // Hangfire is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU Lesser General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU Lesser General Public
14 | // License along with Hangfire. If not, see .
15 |
16 | using System.Threading;
17 |
18 | namespace Hangfire
19 | {
20 | public class JobCancellationToken : IJobCancellationToken
21 | {
22 | private readonly bool _canceled;
23 |
24 | public JobCancellationToken(bool canceled)
25 | {
26 | _canceled = canceled;
27 | ShutdownToken = new CancellationToken(canceled);
28 | }
29 |
30 | public CancellationToken ShutdownToken { get; }
31 |
32 | public static IJobCancellationToken Null => null;
33 |
34 | ///
35 | public void ThrowIfCancellationRequested()
36 | {
37 | ShutdownToken.ThrowIfCancellationRequested();
38 | }
39 | }
40 | }
--------------------------------------------------------------------------------
/src/Hangfire.Core/JobCancellationTokenExtensions.cs:
--------------------------------------------------------------------------------
1 | // This file is part of Hangfire. Copyright © 2019 Hangfire OÜ.
2 | //
3 | // Hangfire is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Lesser General Public License as
5 | // published by the Free Software Foundation, either version 3
6 | // of the License, or any later version.
7 | //
8 | // Hangfire is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU Lesser General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU Lesser General Public
14 | // License along with Hangfire. If not, see .
15 |
16 | using Hangfire.Server;
17 |
18 | namespace Hangfire
19 | {
20 | internal static class JobCancellationTokenExtensions
21 | {
22 | public static bool IsAborted(this IJobCancellationToken jobCancellationToken)
23 | {
24 | if (jobCancellationToken is ServerJobCancellationToken serverJobCancellationToken)
25 | {
26 | // for ServerJobCancellationToken we may simply check IsAborted property
27 | // to prevent unnecessary creation of the linked CancellationTokenSource
28 | return serverJobCancellationToken.IsAborted;
29 | }
30 |
31 | return false;
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/Hangfire.Core/JobContinuationOptions.cs:
--------------------------------------------------------------------------------
1 | // This file is part of Hangfire. Copyright © 2013-2014 Hangfire OÜ.
2 | //
3 | // Hangfire is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Lesser General Public License as
5 | // published by the Free Software Foundation, either version 3
6 | // of the License, or any later version.
7 | //
8 | // Hangfire is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU Lesser General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU Lesser General Public
14 | // License along with Hangfire. If not, see .
15 |
16 | using System;
17 |
18 | namespace Hangfire
19 | {
20 | [Flags]
21 | public enum JobContinuationOptions
22 | {
23 | OnAnyFinishedState = 0,
24 | OnlyOnSucceededState = 1,
25 | OnlyOnDeletedState = 2,
26 | }
27 | }
--------------------------------------------------------------------------------
/src/Hangfire.Core/Obsolete/IAuthorizationFilter.cs:
--------------------------------------------------------------------------------
1 | // This file is part of Hangfire. Copyright © 2013-2014 Hangfire OÜ.
2 | //
3 | // Hangfire is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Lesser General Public License as
5 | // published by the Free Software Foundation, either version 3
6 | // of the License, or any later version.
7 | //
8 | // Hangfire is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU Lesser General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU Lesser General Public
14 | // License along with Hangfire. If not, see .
15 |
16 | using System;
17 | using System.Collections.Generic;
18 | using Hangfire.Annotations;
19 |
20 | // ReSharper disable once CheckNamespace
21 | namespace Hangfire.Dashboard
22 | {
23 | [Obsolete("Please use `IDashboardAuthorizationFilter` instead. Will be removed in 2.0.0.")]
24 | public interface IAuthorizationFilter
25 | {
26 | bool Authorize([NotNull] IDictionary owinEnvironment);
27 | }
28 | }
--------------------------------------------------------------------------------
/src/Hangfire.Core/Obsolete/IRequestDispatcher.cs:
--------------------------------------------------------------------------------
1 | // This file is part of Hangfire. Copyright © 2013-2014 Hangfire OÜ.
2 | //
3 | // Hangfire is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Lesser General Public License as
5 | // published by the Free Software Foundation, either version 3
6 | // of the License, or any later version.
7 | //
8 | // Hangfire is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU Lesser General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU Lesser General Public
14 | // License along with Hangfire. If not, see .
15 |
16 | using System;
17 | using System.Threading.Tasks;
18 |
19 | // ReSharper disable once CheckNamespace
20 | namespace Hangfire.Dashboard
21 | {
22 | [Obsolete("Use the `IDashboardDispatcher` interface instead. Will be removed in 2.0.0.")]
23 | public interface IRequestDispatcher
24 | {
25 | Task Dispatch(RequestDispatcherContext context);
26 | }
27 | }
--------------------------------------------------------------------------------
/src/Hangfire.Core/Obsolete/IServerComponent.cs:
--------------------------------------------------------------------------------
1 | // This file is part of Hangfire. Copyright © 2013-2014 Hangfire OÜ.
2 | //
3 | // Hangfire is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Lesser General Public License as
5 | // published by the Free Software Foundation, either version 3
6 | // of the License, or any later version.
7 | //
8 | // Hangfire is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU Lesser General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU Lesser General Public
14 | // License along with Hangfire. If not, see .
15 |
16 | using System;
17 | using System.Threading;
18 |
19 | // ReSharper disable once CheckNamespace
20 | namespace Hangfire.Server
21 | {
22 | ///
23 | [Obsolete("Please use the `IBackgroundProcess` interface where you can. Will be removed in 2.0.0.")]
24 | public interface IServerComponent : IServerProcess
25 | {
26 | void Execute(CancellationToken cancellationToken);
27 | }
28 | }
--------------------------------------------------------------------------------
/src/Hangfire.Core/Obsolete/IServerProcess.cs:
--------------------------------------------------------------------------------
1 | // This file is part of Hangfire. Copyright © 2013-2014 Hangfire OÜ.
2 | //
3 | // Hangfire is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Lesser General Public License as
5 | // published by the Free Software Foundation, either version 3
6 | // of the License, or any later version.
7 | //
8 | // Hangfire is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU Lesser General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU Lesser General Public
14 | // License along with Hangfire. If not, see .
15 |
16 | using System;
17 |
18 | // ReSharper disable once CheckNamespace
19 | namespace Hangfire.Server
20 | {
21 | ///
22 | [Obsolete("Please use the `IBackgroundProcess` interface where you can. Will be removed in 2.0.0.")]
23 | public interface IServerProcess
24 | {
25 | }
26 | }
--------------------------------------------------------------------------------
/src/Hangfire.Core/Obsolete/RequestDispatcherWrapper.cs:
--------------------------------------------------------------------------------
1 | // This file is part of Hangfire. Copyright © 2016 Hangfire OÜ.
2 | //
3 | // Hangfire is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Lesser General Public License as
5 | // published by the Free Software Foundation, either version 3
6 | // of the License, or any later version.
7 | //
8 | // Hangfire is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU Lesser General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU Lesser General Public
14 | // License along with Hangfire. If not, see .
15 |
16 | using System;
17 | using System.Threading.Tasks;
18 | using Hangfire.Annotations;
19 |
20 | // ReSharper disable once CheckNamespace
21 | namespace Hangfire.Dashboard
22 | {
23 | [Obsolete("Use IDashboardDispatcher-based dispatchers instead. Will be removed in 2.0.0.")]
24 | public class RequestDispatcherWrapper : IDashboardDispatcher
25 | {
26 | private readonly IRequestDispatcher _dispatcher;
27 |
28 | public RequestDispatcherWrapper([NotNull] IRequestDispatcher dispatcher)
29 | {
30 | if (dispatcher == null) throw new ArgumentNullException(nameof(dispatcher));
31 | _dispatcher = dispatcher;
32 | }
33 |
34 | public Task Dispatch(DashboardContext context)
35 | {
36 | return _dispatcher.Dispatch(RequestDispatcherContext.FromDashboardContext(context));
37 | }
38 | }
39 | }
--------------------------------------------------------------------------------
/src/Hangfire.Core/Processing/IBackgroundDispatcher.cs:
--------------------------------------------------------------------------------
1 | // This file is part of Hangfire. Copyright © 2017 Hangfire OÜ.
2 | //
3 | // Hangfire is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Lesser General Public License as
5 | // published by the Free Software Foundation, either version 3
6 | // of the License, or any later version.
7 | //
8 | // Hangfire is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU Lesser General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU Lesser General Public
14 | // License along with Hangfire. If not, see .
15 |
16 | using System;
17 | using System.Threading;
18 | using System.Threading.Tasks;
19 |
20 | namespace Hangfire.Processing
21 | {
22 | // TODO Replace these methods with WaitHandle property in 2.0.
23 | public interface IBackgroundDispatcher : IDisposable
24 | {
25 | bool Wait(TimeSpan timeout);
26 | Task WaitAsync(TimeSpan timeout, CancellationToken cancellationToken);
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/Hangfire.Core/Processing/IBackgroundExecution.cs:
--------------------------------------------------------------------------------
1 | // This file is part of Hangfire. Copyright © 2017 Hangfire OÜ.
2 | //
3 | // Hangfire is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Lesser General Public License as
5 | // published by the Free Software Foundation, either version 3
6 | // of the License, or any later version.
7 | //
8 | // Hangfire is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU Lesser General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU Lesser General Public
14 | // License along with Hangfire. If not, see .
15 |
16 | using System;
17 | using System.Threading.Tasks;
18 | using Hangfire.Annotations;
19 |
20 | namespace Hangfire.Processing
21 | {
22 | public interface IBackgroundExecution : IDisposable
23 | {
24 | void Run([NotNull] Action callback, [CanBeNull] object state);
25 | Task RunAsync([NotNull] Func callback, [CanBeNull] object state);
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/Hangfire.Core/Profiling/EmptyProfiler.cs:
--------------------------------------------------------------------------------
1 | // This file is part of Hangfire. Copyright © 2019 Hangfire OÜ.
2 | //
3 | // Hangfire is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Lesser General Public License as
5 | // published by the Free Software Foundation, either version 3
6 | // of the License, or any later version.
7 | //
8 | // Hangfire is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU Lesser General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU Lesser General Public
14 | // License along with Hangfire. If not, see .
15 |
16 | using System;
17 |
18 | namespace Hangfire.Profiling
19 | {
20 | internal sealed class EmptyProfiler : IProfiler
21 | {
22 | internal static readonly IProfiler Instance = new EmptyProfiler();
23 |
24 | private EmptyProfiler()
25 | {
26 | }
27 |
28 | public TResult InvokeMeasured(
29 | TInstance instance,
30 | Func action,
31 | Func messageFunc)
32 | {
33 | if (action == null) throw new ArgumentNullException(nameof(action));
34 | return action(instance);
35 | }
36 | }
37 | }
--------------------------------------------------------------------------------
/src/Hangfire.Core/Profiling/IProfiler.cs:
--------------------------------------------------------------------------------
1 | // This file is part of Hangfire. Copyright © 2019 Hangfire OÜ.
2 | //
3 | // Hangfire is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Lesser General Public License as
5 | // published by the Free Software Foundation, either version 3
6 | // of the License, or any later version.
7 | //
8 | // Hangfire is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU Lesser General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU Lesser General Public
14 | // License along with Hangfire. If not, see .
15 |
16 | using System;
17 | using Hangfire.Annotations;
18 |
19 | namespace Hangfire.Profiling
20 | {
21 | // TODO: Merge this with logging
22 | internal interface IProfiler
23 | {
24 | // TODO: Replace method with some eventId
25 | TResult InvokeMeasured(
26 | [CanBeNull] TInstance instance,
27 | [NotNull, InstantHandle] Func action,
28 | [CanBeNull] Func messageFunc = null);
29 | }
30 | }
--------------------------------------------------------------------------------
/src/Hangfire.Core/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Reflection;
3 | using System.Resources;
4 | using System.Runtime.CompilerServices;
5 | using System.Runtime.InteropServices;
6 |
7 | [assembly: AssemblyTitle("Hangfire")]
8 | [assembly: AssemblyDescription("Core classes of Hangfire that are independent of any framework.")]
9 | [assembly: Guid("4deecd4f-19f6-426b-aa87-6cd1a03eaa48")]
10 | [assembly: CLSCompliant(true)]
11 | [assembly: InternalsVisibleTo("Hangfire.Core.Tests")]
12 | [assembly: NeutralResourcesLanguage("en")]
13 |
14 | // Allow the generation of mocks for internal types
15 | [assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")]
--------------------------------------------------------------------------------
/src/Hangfire.Core/Razor.build:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Hangfire
6 | true
7 | $(MsBuildProjectDirectory)\
8 |
9 |
10 |
--------------------------------------------------------------------------------
/src/Hangfire.Core/Server/IBackgroundJobPerformer.cs:
--------------------------------------------------------------------------------
1 | // This file is part of Hangfire. Copyright © 2013-2014 Hangfire OÜ.
2 | //
3 | // Hangfire is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Lesser General Public License as
5 | // published by the Free Software Foundation, either version 3
6 | // of the License, or any later version.
7 | //
8 | // Hangfire is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU Lesser General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU Lesser General Public
14 | // License along with Hangfire. If not, see .
15 |
16 | namespace Hangfire.Server
17 | {
18 | public interface IBackgroundJobPerformer
19 | {
20 | object Perform(PerformContext context);
21 | }
22 | }
--------------------------------------------------------------------------------
/src/Hangfire.Core/Server/IBackgroundProcessAsync.cs:
--------------------------------------------------------------------------------
1 | // This file is part of Hangfire. Copyright © 2017 Hangfire OÜ.
2 | //
3 | // Hangfire is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Lesser General Public License as
5 | // published by the Free Software Foundation, either version 3
6 | // of the License, or any later version.
7 | //
8 | // Hangfire is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU Lesser General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU Lesser General Public
14 | // License along with Hangfire. If not, see .
15 |
16 | using System.Threading.Tasks;
17 | using Hangfire.Annotations;
18 |
19 | namespace Hangfire.Server
20 | {
21 | public interface IBackgroundProcessAsync
22 | {
23 | Task ExecuteAsync([NotNull] BackgroundProcessContext context);
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/Hangfire.Core/Server/IBackgroundProcessDispatcherBuilder.cs:
--------------------------------------------------------------------------------
1 | // This file is part of Hangfire. Copyright © 2017 Hangfire OÜ.
2 | //
3 | // Hangfire is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Lesser General Public License as
5 | // published by the Free Software Foundation, either version 3
6 | // of the License, or any later version.
7 | //
8 | // Hangfire is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU Lesser General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU Lesser General Public
14 | // License along with Hangfire. If not, see .
15 |
16 | using Hangfire.Annotations;
17 | using Hangfire.Processing;
18 |
19 | namespace Hangfire.Server
20 | {
21 | public interface IBackgroundProcessDispatcherBuilder
22 | {
23 | IBackgroundDispatcher Create([NotNull] BackgroundServerContext context, [NotNull] BackgroundProcessingServerOptions options);
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/Hangfire.Core/Server/IBackgroundProcessingServer.cs:
--------------------------------------------------------------------------------
1 | // This file is part of Hangfire. Copyright © 2017 Hangfire OÜ.
2 | //
3 | // Hangfire is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Lesser General Public License as
5 | // published by the Free Software Foundation, either version 3
6 | // of the License, or any later version.
7 | //
8 | // Hangfire is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU Lesser General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU Lesser General Public
14 | // License along with Hangfire. If not, see .
15 |
16 | using System;
17 | using System.Threading;
18 | using System.Threading.Tasks;
19 |
20 | namespace Hangfire.Server
21 | {
22 | public interface IBackgroundProcessingServer : IDisposable
23 | {
24 | void SendStop();
25 |
26 | bool WaitForShutdown(TimeSpan timeout);
27 | Task WaitForShutdownAsync(CancellationToken cancellationToken);
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/Hangfire.Core/Server/IBackgroundServerProcess.cs:
--------------------------------------------------------------------------------
1 | // This file is part of Hangfire. Copyright © 2017 Hangfire OÜ.
2 | //
3 | // Hangfire is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Lesser General Public License as
5 | // published by the Free Software Foundation, either version 3
6 | // of the License, or any later version.
7 | //
8 | // Hangfire is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU Lesser General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU Lesser General Public
14 | // License along with Hangfire. If not, see .
15 |
16 | using System;
17 | using System.Threading;
18 | using Hangfire.Processing;
19 |
20 | namespace Hangfire.Server
21 | {
22 | internal interface IBackgroundServerProcess
23 | {
24 | void Execute(
25 | Guid executionId,
26 | BackgroundExecution execution,
27 | CancellationToken stoppingToken,
28 | CancellationToken stoppedToken,
29 | CancellationToken shutdownToken);
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/Hangfire.Core/Server/IServerExceptionFilter.cs:
--------------------------------------------------------------------------------
1 | // This file is part of Hangfire. Copyright © 2013-2014 Hangfire OÜ.
2 | //
3 | // Hangfire is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Lesser General Public License as
5 | // published by the Free Software Foundation, either version 3
6 | // of the License, or any later version.
7 | //
8 | // Hangfire is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU Lesser General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU Lesser General Public
14 | // License along with Hangfire. If not, see .
15 |
16 | namespace Hangfire.Server
17 | {
18 | ///
19 | /// Defines methods that are required for the server exception filter.
20 | ///
21 | public interface IServerExceptionFilter
22 | {
23 | ///
24 | /// Called when an exception occurred during the performance of the job.
25 | ///
26 | /// The filter context.
27 | void OnServerException(ServerExceptionContext filterContext);
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/Hangfire.Core/Server/IServerFilter.cs:
--------------------------------------------------------------------------------
1 | // This file is part of Hangfire. Copyright © 2013-2014 Hangfire OÜ.
2 | //
3 | // Hangfire is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Lesser General Public License as
5 | // published by the Free Software Foundation, either version 3
6 | // of the License, or any later version.
7 | //
8 | // Hangfire is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU Lesser General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU Lesser General Public
14 | // License along with Hangfire. If not, see .
15 |
16 | namespace Hangfire.Server
17 | {
18 | ///
19 | /// Defines methods that are required for a server filter.
20 | ///
21 | public interface IServerFilter
22 | {
23 | ///
24 | /// Called before the performance of the job.
25 | ///
26 | /// The filter context.
27 | void OnPerforming(PerformingContext context);
28 |
29 | ///
30 | /// Called after the performance of the job.
31 | ///
32 | /// The filter context.
33 | void OnPerformed(PerformedContext context);
34 | }
35 | }
--------------------------------------------------------------------------------
/src/Hangfire.Core/Server/PerformingContext.cs:
--------------------------------------------------------------------------------
1 | // This file is part of Hangfire. Copyright © 2013-2014 Hangfire OÜ.
2 | //
3 | // Hangfire is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Lesser General Public License as
5 | // published by the Free Software Foundation, either version 3
6 | // of the License, or any later version.
7 | //
8 | // Hangfire is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU Lesser General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU Lesser General Public
14 | // License along with Hangfire. If not, see .
15 |
16 | namespace Hangfire.Server
17 | {
18 | ///
19 | /// Provides the context for the
20 | /// method of the interface.
21 | ///
22 | public class PerformingContext : PerformContext
23 | {
24 | public PerformingContext(PerformContext context)
25 | : base(context)
26 | {
27 | }
28 |
29 | ///
30 | /// Gets or sets a value that indicates that this
31 | /// object was canceled.
32 | ///
33 | public bool Canceled { get; set; }
34 | }
35 | }
--------------------------------------------------------------------------------
/src/Hangfire.Core/Server/ServerContext.cs:
--------------------------------------------------------------------------------
1 | // This file is part of Hangfire. Copyright © 2013-2014 Hangfire OÜ.
2 | //
3 | // Hangfire is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Lesser General Public License as
5 | // published by the Free Software Foundation, either version 3
6 | // of the License, or any later version.
7 | //
8 | // Hangfire is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU Lesser General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU Lesser General Public
14 | // License along with Hangfire. If not, see .
15 |
16 | namespace Hangfire.Server
17 | {
18 | public class ServerContext
19 | {
20 | public ServerContext()
21 | {
22 | Queues = [];
23 | WorkerCount = -1;
24 | }
25 |
26 | public int WorkerCount { get; set; }
27 | public string[] Queues { get; set; }
28 | }
29 | }
--------------------------------------------------------------------------------
/src/Hangfire.Core/States/IApplyStateFilter.cs:
--------------------------------------------------------------------------------
1 | // This file is part of Hangfire. Copyright © 2013-2014 Hangfire OÜ.
2 | //
3 | // Hangfire is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Lesser General Public License as
5 | // published by the Free Software Foundation, either version 3
6 | // of the License, or any later version.
7 | //
8 | // Hangfire is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU Lesser General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU Lesser General Public
14 | // License along with Hangfire. If not, see .
15 |
16 | using Hangfire.Storage;
17 |
18 | namespace Hangfire.States
19 | {
20 | ///
21 | /// Provides methods that are required for a state changed filter.
22 | ///
23 | public interface IApplyStateFilter
24 | {
25 | ///
26 | /// Called after the specified state was applied
27 | /// to the job within the given transaction.
28 | ///
29 | void OnStateApplied(
30 | ApplyStateContext context, IWriteOnlyTransaction transaction);
31 |
32 | ///
33 | /// Called when the state with specified state was
34 | /// unapplied from the job within the given transaction.
35 | ///
36 | void OnStateUnapplied(
37 | ApplyStateContext context, IWriteOnlyTransaction transaction);
38 | }
39 | }
--------------------------------------------------------------------------------
/src/Hangfire.Core/States/IBackgroundJobStateChanger.cs:
--------------------------------------------------------------------------------
1 | // This file is part of Hangfire. Copyright © 2013-2014 Hangfire OÜ.
2 | //
3 | // Hangfire is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Lesser General Public License as
5 | // published by the Free Software Foundation, either version 3
6 | // of the License, or any later version.
7 | //
8 | // Hangfire is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU Lesser General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU Lesser General Public
14 | // License along with Hangfire. If not, see .
15 |
16 | namespace Hangfire.States
17 | {
18 | public interface IBackgroundJobStateChanger
19 | {
20 | ///
21 | /// Attempts to change the state of a job, respecting any applicable job filters and state handlers.
22 | ///
23 | /// Null if a constraint has failed, otherwise the final applied state
24 | /// Also ensures that the job data can be loaded for this job
25 | IState ChangeState(StateChangeContext context);
26 | }
27 | }
--------------------------------------------------------------------------------
/src/Hangfire.Core/States/IElectStateFilter.cs:
--------------------------------------------------------------------------------
1 | // This file is part of Hangfire. Copyright © 2013-2014 Hangfire OÜ.
2 | //
3 | // Hangfire is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Lesser General Public License as
5 | // published by the Free Software Foundation, either version 3
6 | // of the License, or any later version.
7 | //
8 | // Hangfire is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU Lesser General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU Lesser General Public
14 | // License along with Hangfire. If not, see .
15 |
16 | namespace Hangfire.States
17 | {
18 | ///
19 | /// Defines methods that are required for a state changing filter.
20 | ///
21 | public interface IElectStateFilter
22 | {
23 | ///
24 | /// Called when the current state of the job is being changed to the
25 | /// specified candidate state.
26 | /// This state change could be intercepted and the final state could
27 | /// be changed through setting the different state in the context
28 | /// in an implementation of this method.
29 | ///
30 | void OnStateElection(ElectStateContext context);
31 | }
32 | }
--------------------------------------------------------------------------------
/src/Hangfire.Core/States/IStateMachine.cs:
--------------------------------------------------------------------------------
1 | // This file is part of Hangfire. Copyright © 2013-2014 Hangfire OÜ.
2 | //
3 | // Hangfire is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Lesser General Public License as
5 | // published by the Free Software Foundation, either version 3
6 | // of the License, or any later version.
7 | //
8 | // Hangfire is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU Lesser General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU Lesser General Public
14 | // License along with Hangfire. If not, see .
15 |
16 | namespace Hangfire.States
17 | {
18 | ///
19 | /// Provides a mechanism for running state election and state applying processes.
20 | ///
21 | ///
22 | ///
23 | public interface IStateMachine
24 | {
25 | ///
26 | /// Performs the state applying process, where a current background job
27 | /// will be moved to the elected state.
28 | ///
29 | /// The context of a state applying process.
30 | IState ApplyState(ApplyStateContext context);
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/Hangfire.Core/Storage/IFetchedJob.cs:
--------------------------------------------------------------------------------
1 | // This file is part of Hangfire. Copyright © 2013-2014 Hangfire OÜ.
2 | //
3 | // Hangfire is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Lesser General Public License as
5 | // published by the Free Software Foundation, either version 3
6 | // of the License, or any later version.
7 | //
8 | // Hangfire is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU Lesser General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU Lesser General Public
14 | // License along with Hangfire. If not, see .
15 |
16 | using System;
17 |
18 | namespace Hangfire.Storage
19 | {
20 | public interface IFetchedJob : IDisposable
21 | {
22 | string JobId { get; }
23 |
24 | void RemoveFromQueue();
25 | void Requeue();
26 | }
27 | }
--------------------------------------------------------------------------------
/src/Hangfire.Core/Storage/JobData.cs:
--------------------------------------------------------------------------------
1 | // This file is part of Hangfire. Copyright © 2013-2014 Hangfire OÜ.
2 | //
3 | // Hangfire is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Lesser General Public License as
5 | // published by the Free Software Foundation, either version 3
6 | // of the License, or any later version.
7 | //
8 | // Hangfire is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU Lesser General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU Lesser General Public
14 | // License along with Hangfire. If not, see .
15 |
16 | using System;
17 | using System.Collections.Generic;
18 | using Hangfire.Common;
19 |
20 | namespace Hangfire.Storage
21 | {
22 | public class JobData
23 | {
24 | public string State { get; set; }
25 | public Job Job { get; set; }
26 | public InvocationData InvocationData { get; set; }
27 | public DateTime CreatedAt { get; set; }
28 | public IReadOnlyDictionary ParametersSnapshot { get; set; }
29 |
30 | public JobLoadException LoadException { get; set; }
31 |
32 | public void EnsureLoaded()
33 | {
34 | if (LoadException != null)
35 | {
36 | throw LoadException;
37 | }
38 | }
39 | }
40 | }
--------------------------------------------------------------------------------
/src/Hangfire.Core/Storage/Monitoring/AwaitingJobDto.cs:
--------------------------------------------------------------------------------
1 | // This file is part of Hangfire. Copyright © 2022 Hangfire OÜ.
2 | //
3 | // Hangfire is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Lesser General Public License as
5 | // published by the Free Software Foundation, either version 3
6 | // of the License, or any later version.
7 | //
8 | // Hangfire is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU Lesser General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU Lesser General Public
14 | // License along with Hangfire. If not, see .
15 |
16 | using System;
17 | using System.Collections.Generic;
18 | using Hangfire.Common;
19 |
20 | namespace Hangfire.Storage.Monitoring
21 | {
22 | public class AwaitingJobDto
23 | {
24 | public AwaitingJobDto()
25 | {
26 | InAwaitingState = true;
27 | }
28 |
29 | public Job Job { get; set; }
30 | public JobLoadException LoadException { get; set; }
31 | public InvocationData InvocationData { get; set; }
32 | public DateTime? AwaitingAt { get; set; }
33 | public bool InAwaitingState { get; set; }
34 | public IDictionary StateData { get; set; }
35 | public string ParentStateName { get; set; }
36 | }
37 | }
--------------------------------------------------------------------------------
/src/Hangfire.Core/Storage/Monitoring/DeletedJobDto.cs:
--------------------------------------------------------------------------------
1 | // This file is part of Hangfire. Copyright © 2013-2014 Hangfire OÜ.
2 | //
3 | // Hangfire is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Lesser General Public License as
5 | // published by the Free Software Foundation, either version 3
6 | // of the License, or any later version.
7 | //
8 | // Hangfire is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU Lesser General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU Lesser General Public
14 | // License along with Hangfire. If not, see .
15 |
16 | using System;
17 | using System.Collections.Generic;
18 | using Hangfire.Common;
19 |
20 | namespace Hangfire.Storage.Monitoring
21 | {
22 | public class DeletedJobDto
23 | {
24 | public DeletedJobDto()
25 | {
26 | InDeletedState = true;
27 | }
28 |
29 | public Job Job { get; set; }
30 | public JobLoadException LoadException { get; set; }
31 | public InvocationData InvocationData { get; set; }
32 | public DateTime? DeletedAt { get; set; }
33 | public bool InDeletedState { get; set; }
34 | public IDictionary StateData { get; set; }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/Hangfire.Core/Storage/Monitoring/EnqueuedJobDto.cs:
--------------------------------------------------------------------------------
1 | // This file is part of Hangfire. Copyright © 2013-2014 Hangfire OÜ.
2 | //
3 | // Hangfire is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Lesser General Public License as
5 | // published by the Free Software Foundation, either version 3
6 | // of the License, or any later version.
7 | //
8 | // Hangfire is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU Lesser General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU Lesser General Public
14 | // License along with Hangfire. If not, see .
15 |
16 | using System;
17 | using System.Collections.Generic;
18 | using Hangfire.Common;
19 |
20 | namespace Hangfire.Storage.Monitoring
21 | {
22 | public class EnqueuedJobDto
23 | {
24 | public EnqueuedJobDto()
25 | {
26 | InEnqueuedState = true;
27 | }
28 |
29 | public Job Job { get; set; }
30 | public JobLoadException LoadException { get; set; }
31 | public InvocationData InvocationData { get; set; }
32 | public string State { get; set; }
33 | public DateTime? EnqueuedAt { get; set; }
34 | public bool InEnqueuedState { get; set; }
35 | public IDictionary StateData { get; set; }
36 | }
37 | }
--------------------------------------------------------------------------------
/src/Hangfire.Core/Storage/Monitoring/FailedJobDto.cs:
--------------------------------------------------------------------------------
1 | // This file is part of Hangfire. Copyright © 2013-2014 Hangfire OÜ.
2 | //
3 | // Hangfire is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Lesser General Public License as
5 | // published by the Free Software Foundation, either version 3
6 | // of the License, or any later version.
7 | //
8 | // Hangfire is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU Lesser General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU Lesser General Public
14 | // License along with Hangfire. If not, see .
15 |
16 | using System;
17 | using System.Collections.Generic;
18 | using Hangfire.Common;
19 |
20 | namespace Hangfire.Storage.Monitoring
21 | {
22 | public class FailedJobDto
23 | {
24 | public FailedJobDto()
25 | {
26 | InFailedState = true;
27 | }
28 |
29 | public Job Job { get; set; }
30 | public JobLoadException LoadException { get; set; }
31 | public InvocationData InvocationData { get; set; }
32 | public string Reason { get; set; }
33 | public DateTime? FailedAt { get; set; }
34 | public string ExceptionType { get; set; }
35 | public string ExceptionMessage { get; set; }
36 | public string ExceptionDetails { get; set; }
37 | public bool InFailedState { get; set; }
38 | public IDictionary StateData { get; set; }
39 | }
40 | }
--------------------------------------------------------------------------------
/src/Hangfire.Core/Storage/Monitoring/FetchedJobDto.cs:
--------------------------------------------------------------------------------
1 | // This file is part of Hangfire. Copyright © 2013-2014 Hangfire OÜ.
2 | //
3 | // Hangfire is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Lesser General Public License as
5 | // published by the Free Software Foundation, either version 3
6 | // of the License, or any later version.
7 | //
8 | // Hangfire is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU Lesser General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU Lesser General Public
14 | // License along with Hangfire. If not, see .
15 |
16 | using System;
17 | using Hangfire.Common;
18 |
19 | namespace Hangfire.Storage.Monitoring
20 | {
21 | public class FetchedJobDto
22 | {
23 | public Job Job { get; set; }
24 | public JobLoadException LoadException { get; set; }
25 | public InvocationData InvocationData { get; set; }
26 | public string State { get; set; }
27 | public DateTime? FetchedAt { get; set; }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/Hangfire.Core/Storage/Monitoring/JobDetailsDto.cs:
--------------------------------------------------------------------------------
1 | // This file is part of Hangfire. Copyright © 2013-2014 Hangfire OÜ.
2 | //
3 | // Hangfire is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Lesser General Public License as
5 | // published by the Free Software Foundation, either version 3
6 | // of the License, or any later version.
7 | //
8 | // Hangfire is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU Lesser General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU Lesser General Public
14 | // License along with Hangfire. If not, see .
15 |
16 | using System;
17 | using System.Collections.Generic;
18 | using Hangfire.Common;
19 |
20 | namespace Hangfire.Storage.Monitoring
21 | {
22 | public class JobDetailsDto
23 | {
24 | public Job Job { get; set; }
25 | public JobLoadException LoadException { get; set; }
26 | public InvocationData InvocationData { get; set; }
27 | public DateTime? CreatedAt { get; set; }
28 | public IDictionary Properties { get; set; }
29 | public IList History { get; set; }
30 | public DateTime? ExpireAt { get; set; }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/Hangfire.Core/Storage/Monitoring/JobList.cs:
--------------------------------------------------------------------------------
1 | // This file is part of Hangfire. Copyright © 2013-2014 Hangfire OÜ.
2 | //
3 | // Hangfire is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Lesser General Public License as
5 | // published by the Free Software Foundation, either version 3
6 | // of the License, or any later version.
7 | //
8 | // Hangfire is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU Lesser General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU Lesser General Public
14 | // License along with Hangfire. If not, see .
15 |
16 | using System.Collections.Generic;
17 |
18 | namespace Hangfire.Storage.Monitoring
19 | {
20 | public class JobList : List>
21 | {
22 | public JobList(IEnumerable> source)
23 | : base(source)
24 | {
25 | }
26 | }
27 | }
--------------------------------------------------------------------------------
/src/Hangfire.Core/Storage/Monitoring/ProcessingJobDto.cs:
--------------------------------------------------------------------------------
1 | // This file is part of Hangfire. Copyright © 2013-2014 Hangfire OÜ.
2 | //
3 | // Hangfire is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Lesser General Public License as
5 | // published by the Free Software Foundation, either version 3
6 | // of the License, or any later version.
7 | //
8 | // Hangfire is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU Lesser General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU Lesser General Public
14 | // License along with Hangfire. If not, see .
15 |
16 | using System;
17 | using System.Collections.Generic;
18 | using Hangfire.Common;
19 |
20 | namespace Hangfire.Storage.Monitoring
21 | {
22 | public class ProcessingJobDto
23 | {
24 | public ProcessingJobDto()
25 | {
26 | InProcessingState = true;
27 | }
28 |
29 | public Job Job { get; set; }
30 | public JobLoadException LoadException { get; set; }
31 | public InvocationData InvocationData { get; set; }
32 | public bool InProcessingState { get; set; }
33 | public string ServerId { get; set; }
34 | public DateTime? StartedAt { get; set; }
35 | public IDictionary StateData { get; set; }
36 | }
37 | }
--------------------------------------------------------------------------------
/src/Hangfire.Core/Storage/Monitoring/QueueWithTopEnqueuedJobsDto.cs:
--------------------------------------------------------------------------------
1 | // This file is part of Hangfire. Copyright © 2013-2014 Hangfire OÜ.
2 | //
3 | // Hangfire is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Lesser General Public License as
5 | // published by the Free Software Foundation, either version 3
6 | // of the License, or any later version.
7 | //
8 | // Hangfire is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU Lesser General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU Lesser General Public
14 | // License along with Hangfire. If not, see .
15 |
16 | namespace Hangfire.Storage.Monitoring
17 | {
18 | public class QueueWithTopEnqueuedJobsDto
19 | {
20 | public string Name { get; set; }
21 | public long Length { get; set; }
22 | public long? Fetched { get; set; }
23 | public JobList FirstJobs { get; set; }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/Hangfire.Core/Storage/Monitoring/ScheduledJobDto.cs:
--------------------------------------------------------------------------------
1 | // This file is part of Hangfire. Copyright © 2013-2014 Hangfire OÜ.
2 | //
3 | // Hangfire is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Lesser General Public License as
5 | // published by the Free Software Foundation, either version 3
6 | // of the License, or any later version.
7 | //
8 | // Hangfire is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU Lesser General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU Lesser General Public
14 | // License along with Hangfire. If not, see .
15 |
16 | using System;
17 | using System.Collections.Generic;
18 | using Hangfire.Common;
19 |
20 | namespace Hangfire.Storage.Monitoring
21 | {
22 | public class ScheduledJobDto
23 | {
24 | public ScheduledJobDto()
25 | {
26 | InScheduledState = true;
27 | }
28 |
29 | public Job Job { get; set; }
30 | public JobLoadException LoadException { get; set; }
31 | public InvocationData InvocationData { get; set; }
32 | public DateTime EnqueueAt { get; set; }
33 | public DateTime? ScheduledAt { get; set; }
34 | public bool InScheduledState { get; set; }
35 | public IDictionary StateData { get; set; }
36 | }
37 | }
--------------------------------------------------------------------------------
/src/Hangfire.Core/Storage/Monitoring/ServerDto.cs:
--------------------------------------------------------------------------------
1 | // This file is part of Hangfire. Copyright © 2013-2014 Hangfire OÜ.
2 | //
3 | // Hangfire is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Lesser General Public License as
5 | // published by the Free Software Foundation, either version 3
6 | // of the License, or any later version.
7 | //
8 | // Hangfire is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU Lesser General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU Lesser General Public
14 | // License along with Hangfire. If not, see .
15 |
16 | using System;
17 | using System.Collections.Generic;
18 |
19 | namespace Hangfire.Storage.Monitoring
20 | {
21 | public class ServerDto
22 | {
23 | public string Name { get; set; }
24 | public int WorkersCount { get; set; }
25 | public DateTime StartedAt { get; set; }
26 | public IList Queues { get; set; }
27 | public DateTime? Heartbeat { get; set; }
28 | }
29 | }
--------------------------------------------------------------------------------
/src/Hangfire.Core/Storage/Monitoring/StateHistoryDto.cs:
--------------------------------------------------------------------------------
1 | // This file is part of Hangfire. Copyright © 2013-2014 Hangfire OÜ.
2 | //
3 | // Hangfire is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Lesser General Public License as
5 | // published by the Free Software Foundation, either version 3
6 | // of the License, or any later version.
7 | //
8 | // Hangfire is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU Lesser General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU Lesser General Public
14 | // License along with Hangfire. If not, see .
15 |
16 | using System;
17 | using System.Collections.Generic;
18 |
19 | namespace Hangfire.Storage.Monitoring
20 | {
21 | public class StateHistoryDto
22 | {
23 | public string StateName { get; set; }
24 | public string Reason { get; set; }
25 | public DateTime CreatedAt { get; set; }
26 | public IDictionary Data { get; set; }
27 | }
28 | }
--------------------------------------------------------------------------------
/src/Hangfire.Core/Storage/Monitoring/StatisticsDto.cs:
--------------------------------------------------------------------------------
1 | // This file is part of Hangfire. Copyright © 2013-2014 Hangfire OÜ.
2 | //
3 | // Hangfire is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Lesser General Public License as
5 | // published by the Free Software Foundation, either version 3
6 | // of the License, or any later version.
7 | //
8 | // Hangfire is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU Lesser General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU Lesser General Public
14 | // License along with Hangfire. If not, see .
15 |
16 | namespace Hangfire.Storage.Monitoring
17 | {
18 | public class StatisticsDto
19 | {
20 | public long Servers { get; set; }
21 | public long Recurring { get; set; }
22 | public long Enqueued { get; set; }
23 | public long Queues { get; set; }
24 | public long Scheduled { get; set; }
25 | public long Processing { get; set; }
26 | public long Succeeded { get; set; }
27 | public long Failed { get; set; }
28 | public long Deleted { get; set; }
29 | public long? Retries { get; set; }
30 | public long? Awaiting { get; set; }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/Hangfire.Core/Storage/Monitoring/SucceededJobDto.cs:
--------------------------------------------------------------------------------
1 | // This file is part of Hangfire. Copyright © 2013-2014 Hangfire OÜ.
2 | //
3 | // Hangfire is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Lesser General Public License as
5 | // published by the Free Software Foundation, either version 3
6 | // of the License, or any later version.
7 | //
8 | // Hangfire is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU Lesser General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU Lesser General Public
14 | // License along with Hangfire. If not, see .
15 |
16 | using System;
17 | using System.Collections.Generic;
18 | using Hangfire.Common;
19 |
20 | namespace Hangfire.Storage.Monitoring
21 | {
22 | public class SucceededJobDto
23 | {
24 | public SucceededJobDto()
25 | {
26 | InSucceededState = true;
27 | }
28 |
29 | public Job Job { get; set; }
30 | public JobLoadException LoadException { get; set; }
31 | public InvocationData InvocationData { get; set; }
32 | public object Result { get; set; }
33 | public long? TotalDuration { get; set; }
34 | public DateTime? SucceededAt { get; set; }
35 | public bool InSucceededState { get; set; }
36 | public IDictionary StateData { get; set; }
37 | }
38 | }
--------------------------------------------------------------------------------
/src/Hangfire.Core/Storage/RecurringJobDto.cs:
--------------------------------------------------------------------------------
1 | // This file is part of Hangfire. Copyright © 2013-2014 Hangfire OÜ.
2 | //
3 | // Hangfire is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Lesser General Public License as
5 | // published by the Free Software Foundation, either version 3
6 | // of the License, or any later version.
7 | //
8 | // Hangfire is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU Lesser General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU Lesser General Public
14 | // License along with Hangfire. If not, see .
15 |
16 | using System;
17 | using Hangfire.Common;
18 |
19 | namespace Hangfire.Storage
20 | {
21 | public class RecurringJobDto
22 | {
23 | public string Id { get; set; }
24 | public string Cron { get; set; }
25 | public string Queue { get; set; }
26 | public Job Job { get; set; }
27 | public JobLoadException LoadException { get; set; }
28 | public DateTime? NextExecution { get; set; }
29 | public string LastJobId { get; set; }
30 | public string LastJobState { get; set; }
31 | public DateTime? LastExecution { get; set; }
32 | public DateTime? CreatedAt { get; set; }
33 | public bool Removed { get; set; }
34 | public string TimeZoneId { get; set; }
35 | public string Error { get; set; }
36 | public int RetryAttempt { get; set; }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/Hangfire.Core/Storage/StateData.cs:
--------------------------------------------------------------------------------
1 | // This file is part of Hangfire. Copyright © 2013-2014 Hangfire OÜ.
2 | //
3 | // Hangfire is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Lesser General Public License as
5 | // published by the Free Software Foundation, either version 3
6 | // of the License, or any later version.
7 | //
8 | // Hangfire is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU Lesser General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU Lesser General Public
14 | // License along with Hangfire. If not, see .
15 |
16 | using System.Collections.Generic;
17 | using Hangfire.Annotations;
18 |
19 | // ReSharper disable NotNullMemberIsNotInitialized - Let's trust them!
20 |
21 | namespace Hangfire.Storage
22 | {
23 | public class StateData
24 | {
25 | [NotNull]
26 | public string Name { get; set; }
27 |
28 | [CanBeNull]
29 | public string Reason { get; set; }
30 |
31 | [NotNull]
32 | public IDictionary Data { get; set; }
33 | }
34 | }
--------------------------------------------------------------------------------
/src/Hangfire.NetCore/AspNetCore/AspNetCoreLogProvider.cs:
--------------------------------------------------------------------------------
1 | // This file is part of Hangfire. Copyright © 2016 Hangfire OÜ.
2 | //
3 | // Hangfire is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Lesser General Public License as
5 | // published by the Free Software Foundation, either version 3
6 | // of the License, or any later version.
7 | //
8 | // Hangfire is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU Lesser General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU Lesser General Public
14 | // License along with Hangfire. If not, see .
15 |
16 | using System;
17 | using Hangfire.Annotations;
18 | using Hangfire.Logging;
19 | using Microsoft.Extensions.Logging;
20 |
21 | namespace Hangfire.AspNetCore
22 | {
23 | public class AspNetCoreLogProvider : ILogProvider
24 | {
25 | private readonly ILoggerFactory _loggerFactory;
26 |
27 | public AspNetCoreLogProvider([NotNull] ILoggerFactory loggerFactory)
28 | {
29 | if (loggerFactory == null) throw new ArgumentNullException(nameof(loggerFactory));
30 | _loggerFactory = loggerFactory;
31 | }
32 |
33 | public ILog GetLogger(string name)
34 | {
35 | return new AspNetCoreLog(_loggerFactory.CreateLogger(name));
36 | }
37 | }
38 | }
--------------------------------------------------------------------------------
/src/Hangfire.NetCore/IBackgroundJobClientFactory.cs:
--------------------------------------------------------------------------------
1 | // This file is part of Hangfire. Copyright © 2021 Hangfire OÜ.
2 | //
3 | // Hangfire is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Lesser General Public License as
5 | // published by the Free Software Foundation, either version 3
6 | // of the License, or any later version.
7 | //
8 | // Hangfire is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU Lesser General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU Lesser General Public
14 | // License along with Hangfire. If not, see .
15 |
16 | namespace Hangfire
17 | {
18 | public interface IBackgroundJobClientFactoryV2 : IBackgroundJobClientFactory
19 | {
20 | IBackgroundJobClientV2 GetClientV2(JobStorage storage);
21 | }
22 |
23 | public interface IBackgroundJobClientFactory
24 | {
25 | IBackgroundJobClient GetClient(JobStorage storage);
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/Hangfire.NetCore/IRecurringJobManagerFactory.cs:
--------------------------------------------------------------------------------
1 | // This file is part of Hangfire. Copyright © 2021 Hangfire OÜ.
2 | //
3 | // Hangfire is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Lesser General Public License as
5 | // published by the Free Software Foundation, either version 3
6 | // of the License, or any later version.
7 | //
8 | // Hangfire is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU Lesser General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU Lesser General Public
14 | // License along with Hangfire. If not, see .
15 |
16 | namespace Hangfire
17 | {
18 | public interface IRecurringJobManagerFactoryV2 : IRecurringJobManagerFactory
19 | {
20 | IRecurringJobManagerV2 GetManagerV2(JobStorage storage);
21 | }
22 |
23 | public interface IRecurringJobManagerFactory
24 | {
25 | IRecurringJobManager GetManager(JobStorage storage);
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/Hangfire.SqlServer.Msmq/Hangfire.SqlServer.Msmq.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | net451
4 | true
5 | Hangfire.SqlServer.Msmq
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/src/Hangfire.SqlServer.Msmq/IMsmqTransaction.cs:
--------------------------------------------------------------------------------
1 | // This file is part of Hangfire. Copyright © 2013-2014 Hangfire OÜ.
2 | //
3 | // Hangfire is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Lesser General Public License as
5 | // published by the Free Software Foundation, either version 3
6 | // of the License, or any later version.
7 | //
8 | // Hangfire is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU Lesser General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU Lesser General Public
14 | // License along with Hangfire. If not, see .
15 |
16 | using System;
17 | using System.Messaging;
18 |
19 | namespace Hangfire.SqlServer.Msmq
20 | {
21 | internal interface IMsmqTransaction : IDisposable
22 | {
23 | Message Receive(MessageQueue queue, TimeSpan timeout);
24 |
25 | void Commit();
26 | void Abort();
27 | }
28 | }
--------------------------------------------------------------------------------
/src/Hangfire.SqlServer.Msmq/MsmqJobQueueProvider.cs:
--------------------------------------------------------------------------------
1 | // This file is part of Hangfire. Copyright © 2013-2014 Hangfire OÜ.
2 | //
3 | // Hangfire is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Lesser General Public License as
5 | // published by the Free Software Foundation, either version 3
6 | // of the License, or any later version.
7 | //
8 | // Hangfire is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU Lesser General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU Lesser General Public
14 | // License along with Hangfire. If not, see .
15 |
16 | using System.Collections.Generic;
17 |
18 | namespace Hangfire.SqlServer.Msmq
19 | {
20 | internal sealed class MsmqJobQueueProvider : IPersistentJobQueueProvider
21 | {
22 | private readonly MsmqJobQueue _jobQueue;
23 | private readonly MsmqJobQueueMonitoringApi _monitoringApi;
24 |
25 | public MsmqJobQueueProvider(string pathPattern, IEnumerable queues, MsmqTransactionType transactionType)
26 | {
27 | _jobQueue = new MsmqJobQueue(pathPattern, transactionType);
28 | _monitoringApi = new MsmqJobQueueMonitoringApi(pathPattern, queues);
29 | }
30 |
31 | public IPersistentJobQueue GetJobQueue()
32 | {
33 | return _jobQueue;
34 | }
35 |
36 | public IPersistentJobQueueMonitoringApi GetJobQueueMonitoringApi()
37 | {
38 | return _monitoringApi;
39 | }
40 | }
41 | }
--------------------------------------------------------------------------------
/src/Hangfire.SqlServer.Msmq/MsmqTransactionType.cs:
--------------------------------------------------------------------------------
1 | // This file is part of Hangfire. Copyright © 2013-2014 Hangfire OÜ.
2 | //
3 | // Hangfire is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Lesser General Public License as
5 | // published by the Free Software Foundation, either version 3
6 | // of the License, or any later version.
7 | //
8 | // Hangfire is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU Lesser General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU Lesser General Public
14 | // License along with Hangfire. If not, see .
15 |
16 | namespace Hangfire.SqlServer.Msmq
17 | {
18 | public enum MsmqTransactionType
19 | {
20 | ///
21 | /// Internal (MSMQ) transaction will be used to fetch pending background
22 | /// jobs, does not support remote queues.
23 | ///
24 | Internal,
25 |
26 | ///
27 | /// External (DTC) transaction will be used to fetch pending background
28 | /// jobs. Supports remote queues, but requires running MSDTC Service.
29 | ///
30 | Dtc
31 | }
32 | }
--------------------------------------------------------------------------------
/src/Hangfire.SqlServer.Msmq/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Reflection;
3 | using System.Runtime.CompilerServices;
4 | using System.Runtime.InteropServices;
5 |
6 | [assembly: AssemblyTitle("Hangfire.SqlServer.MSMQ")]
7 | [assembly: AssemblyDescription("Hangfire MSMQ job queue for SQL Server storage implementation")]
8 | [assembly: Guid("03092b5c-0dfc-4c6c-8422-556bd1cb291e")]
9 | [assembly: CLSCompliant(true)]
10 |
11 | [assembly: InternalsVisibleTo("Hangfire.SqlServer.Msmq.Tests")]
12 | // Allow the generation of mocks for internal types
13 | [assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")]
--------------------------------------------------------------------------------
/src/Hangfire.SqlServer/Constants.cs:
--------------------------------------------------------------------------------
1 | // This file is part of Hangfire. Copyright © 2015 Hangfire OÜ.
2 | //
3 | // Hangfire is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Lesser General Public License as
5 | // published by the Free Software Foundation, either version 3
6 | // of the License, or any later version.
7 | //
8 | // Hangfire is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU Lesser General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU Lesser General Public
14 | // License along with Hangfire. If not, see .
15 |
16 | namespace Hangfire.SqlServer
17 | {
18 | internal sealed class Constants
19 | {
20 | public static readonly string DefaultSchema = "HangFire";
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/Hangfire.SqlServer/DefaultInstall.tt:
--------------------------------------------------------------------------------
1 | <#@ template debug="false" hostspecific="false" language="C#" #>
2 | <#@ assembly name="System.Core" #>
3 | <#@ assembly name="$(TargetPath)" #>
4 | <#@ import namespace="System.Linq" #>
5 | <#@ import namespace="System.Text" #>
6 | <#@ import namespace="System.Collections.Generic" #>
7 | <#@ output extension=".sql" #>
8 |
9 | <#
10 | var script = GetStringResource(
11 | typeof(Hangfire.SqlServer.IPersistentJobQueue).Assembly,
12 | "Hangfire.SqlServer.Install.sql");
13 |
14 | script = script.Replace("$(HangFireSchema)", "HangFire");
15 |
16 | Write(script);
17 | #>
18 |
19 | <#+
20 | private string GetStringResource(System.Reflection.Assembly assembly, string resourceName)
21 | {
22 | using (var stream = assembly.GetManifestResourceStream(resourceName))
23 | {
24 | if (stream == null)
25 | {
26 | throw new InvalidOperationException(String.Format(
27 | "Requested resource `{0}` was not found in the assembly `{1}`.",
28 | resourceName,
29 | assembly));
30 | }
31 |
32 | using (var reader = new System.IO.StreamReader(stream))
33 | {
34 | return reader.ReadToEnd();
35 | }
36 | }
37 | }
38 | #>
39 |
--------------------------------------------------------------------------------
/src/Hangfire.SqlServer/EnqueuedAndFetchedCountDto.cs:
--------------------------------------------------------------------------------
1 | // This file is part of Hangfire. Copyright © 2013-2014 Hangfire OÜ.
2 | //
3 | // Hangfire is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Lesser General Public License as
5 | // published by the Free Software Foundation, either version 3
6 | // of the License, or any later version.
7 | //
8 | // Hangfire is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU Lesser General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU Lesser General Public
14 | // License along with Hangfire. If not, see .
15 |
16 | namespace Hangfire.SqlServer
17 | {
18 | public class EnqueuedAndFetchedCountDto
19 | {
20 | public int? EnqueuedCount { get; set; }
21 | public int? FetchedCount { get; set; }
22 | }
23 | }
--------------------------------------------------------------------------------
/src/Hangfire.SqlServer/Entities/JobParameter.cs:
--------------------------------------------------------------------------------
1 | // This file is part of Hangfire. Copyright © 2013-2014 Hangfire OÜ.
2 | //
3 | // Hangfire is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Lesser General Public License as
5 | // published by the Free Software Foundation, either version 3
6 | // of the License, or any later version.
7 | //
8 | // Hangfire is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU Lesser General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU Lesser General Public
14 | // License along with Hangfire. If not, see .
15 |
16 | namespace Hangfire.SqlServer.Entities
17 | {
18 | internal sealed class JobParameter
19 | {
20 | public long JobId { get; set; }
21 | public string Name { get; set; }
22 | public string Value { get; set; }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/Hangfire.SqlServer/Entities/Server.cs:
--------------------------------------------------------------------------------
1 | // This file is part of Hangfire. Copyright © 2013-2014 Hangfire OÜ.
2 | //
3 | // Hangfire is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Lesser General Public License as
5 | // published by the Free Software Foundation, either version 3
6 | // of the License, or any later version.
7 | //
8 | // Hangfire is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU Lesser General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU Lesser General Public
14 | // License along with Hangfire. If not, see .
15 |
16 | using System;
17 |
18 | namespace Hangfire.SqlServer.Entities
19 | {
20 | internal sealed class Server
21 | {
22 | public string Id { get; set; }
23 | public string Data { get; set; }
24 | public DateTime LastHeartbeat { get; set; }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/Hangfire.SqlServer/Entities/ServerData.cs:
--------------------------------------------------------------------------------
1 | // This file is part of Hangfire. Copyright © 2013-2014 Hangfire OÜ.
2 | //
3 | // Hangfire is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Lesser General Public License as
5 | // published by the Free Software Foundation, either version 3
6 | // of the License, or any later version.
7 | //
8 | // Hangfire is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU Lesser General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU Lesser General Public
14 | // License along with Hangfire. If not, see .
15 |
16 | using System;
17 |
18 | namespace Hangfire.SqlServer.Entities
19 | {
20 | internal sealed class ServerData
21 | {
22 | public int WorkerCount { get; set; }
23 | public string[] Queues { get; set; }
24 | public DateTime? StartedAt { get; set; }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/Hangfire.SqlServer/Entities/SqlHash.cs:
--------------------------------------------------------------------------------
1 | // This file is part of Hangfire. Copyright © 2013-2014 Hangfire OÜ.
2 | //
3 | // Hangfire is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Lesser General Public License as
5 | // published by the Free Software Foundation, either version 3
6 | // of the License, or any later version.
7 | //
8 | // Hangfire is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU Lesser General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU Lesser General Public
14 | // License along with Hangfire. If not, see .
15 |
16 | using System;
17 |
18 | namespace Hangfire.SqlServer.Entities
19 | {
20 | internal sealed class SqlHash
21 | {
22 | public string Key { get; set; }
23 | public string Field { get; set; }
24 | public string Value { get; set; }
25 | public DateTime? ExpireAt { get; set; }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/Hangfire.SqlServer/Entities/SqlJob.cs:
--------------------------------------------------------------------------------
1 | // This file is part of Hangfire. Copyright © 2013-2014 Hangfire OÜ.
2 | //
3 | // Hangfire is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Lesser General Public License as
5 | // published by the Free Software Foundation, either version 3
6 | // of the License, or any later version.
7 | //
8 | // Hangfire is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU Lesser General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU Lesser General Public
14 | // License along with Hangfire. If not, see .
15 |
16 | using System;
17 |
18 | namespace Hangfire.SqlServer.Entities
19 | {
20 | internal sealed class SqlJob
21 | {
22 | public long Id { get; set; }
23 | public string InvocationData { get; set; }
24 | public string Arguments { get; set; }
25 | public DateTime CreatedAt { get; set; }
26 | public DateTime? ExpireAt { get; set; }
27 |
28 | public DateTime? FetchedAt { get; set; }
29 |
30 | public string StateName { get; set; }
31 | public string StateReason { get; set; }
32 | public string StateData { get; set; }
33 | public DateTime? StateChanged { get; set; }
34 | }
35 | }
--------------------------------------------------------------------------------
/src/Hangfire.SqlServer/Entities/SqlState.cs:
--------------------------------------------------------------------------------
1 | // This file is part of Hangfire. Copyright © 2013-2014 Hangfire OÜ.
2 | //
3 | // Hangfire is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Lesser General Public License as
5 | // published by the Free Software Foundation, either version 3
6 | // of the License, or any later version.
7 | //
8 | // Hangfire is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU Lesser General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU Lesser General Public
14 | // License along with Hangfire. If not, see .
15 |
16 | using System;
17 |
18 | namespace Hangfire.SqlServer.Entities
19 | {
20 | internal sealed class SqlState
21 | {
22 | public long JobId { get; set; }
23 | public string Name { get; set; }
24 | public string Reason { get; set; }
25 | public DateTime CreatedAt { get; set; }
26 | public string Data { get; set; }
27 | }
28 | }
--------------------------------------------------------------------------------
/src/Hangfire.SqlServer/IPersistentJobQueue.cs:
--------------------------------------------------------------------------------
1 | // This file is part of Hangfire. Copyright © 2013-2014 Hangfire OÜ.
2 | //
3 | // Hangfire is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Lesser General Public License as
5 | // published by the Free Software Foundation, either version 3
6 | // of the License, or any later version.
7 | //
8 | // Hangfire is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU Lesser General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU Lesser General Public
14 | // License along with Hangfire. If not, see .
15 |
16 | using System.Diagnostics.CodeAnalysis;
17 | using System.Threading;
18 | using Hangfire.Storage;
19 |
20 | namespace Hangfire.SqlServer
21 | {
22 | [SuppressMessage("Naming", "CA1711:Identifiers should not have incorrect suffix", Justification = "This interface represents a persistent queue by design.")]
23 | public interface IPersistentJobQueue
24 | {
25 | IFetchedJob Dequeue(string[] queues, CancellationToken cancellationToken);
26 |
27 | #if FEATURE_TRANSACTIONSCOPE
28 | void Enqueue(System.Data.IDbConnection connection, string queue, string jobId);
29 | #else
30 | void Enqueue(
31 | System.Data.Common.DbConnection connection,
32 | System.Data.Common.DbTransaction transaction,
33 | string queue,
34 | string jobId);
35 | #endif
36 | }
37 | }
--------------------------------------------------------------------------------
/src/Hangfire.SqlServer/IPersistentJobQueueMonitoringApi.cs:
--------------------------------------------------------------------------------
1 | // This file is part of Hangfire. Copyright © 2013-2014 Hangfire OÜ.
2 | //
3 | // Hangfire is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Lesser General Public License as
5 | // published by the Free Software Foundation, either version 3
6 | // of the License, or any later version.
7 | //
8 | // Hangfire is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU Lesser General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU Lesser General Public
14 | // License along with Hangfire. If not, see .
15 |
16 | using System.Collections.Generic;
17 |
18 | namespace Hangfire.SqlServer
19 | {
20 | public interface IPersistentJobQueueMonitoringApi
21 | {
22 | IEnumerable GetQueues();
23 |
24 | IEnumerable GetEnqueuedJobIds(string queue, int from, int perPage);
25 |
26 | // TODO: Extend return type by including DateTime to allow getting the FetchedAt value in 2.0
27 | IEnumerable GetFetchedJobIds(string queue, int from, int perPage);
28 |
29 | EnqueuedAndFetchedCountDto GetEnqueuedAndFetchedCount(string queue);
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/Hangfire.SqlServer/IPersistentJobQueueProvider.cs:
--------------------------------------------------------------------------------
1 | // This file is part of Hangfire. Copyright © 2013-2014 Hangfire OÜ.
2 | //
3 | // Hangfire is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Lesser General Public License as
5 | // published by the Free Software Foundation, either version 3
6 | // of the License, or any later version.
7 | //
8 | // Hangfire is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU Lesser General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU Lesser General Public
14 | // License along with Hangfire. If not, see .
15 |
16 | namespace Hangfire.SqlServer
17 | {
18 | public interface IPersistentJobQueueProvider
19 | {
20 | IPersistentJobQueue GetJobQueue();
21 | IPersistentJobQueueMonitoringApi GetJobQueueMonitoringApi();
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/Hangfire.SqlServer/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Reflection;
3 | using System.Runtime.CompilerServices;
4 | using System.Runtime.InteropServices;
5 |
6 | [assembly: AssemblyTitle("Hangfire.SqlServer")]
7 | [assembly: AssemblyDescription("SQL Server job storage for Hangfire")]
8 | [assembly: Guid("3d96bf2f-8854-4872-aee3-faf81d121a4d")]
9 | [assembly: CLSCompliant(true)]
10 |
11 | [assembly: InternalsVisibleTo("Hangfire.SqlServer.Tests")]
12 | // Allow the generation of mocks for internal types
13 | [assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")]
14 |
--------------------------------------------------------------------------------
/src/Hangfire.SqlServer/TimestampHelper.cs:
--------------------------------------------------------------------------------
1 | // This file is part of Hangfire. Copyright © 2021 Hangfire OÜ.
2 | //
3 | // Hangfire is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Lesser General Public License as
5 | // published by the Free Software Foundation, either version 3
6 | // of the License, or any later version.
7 | //
8 | // Hangfire is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU Lesser General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU Lesser General Public
14 | // License along with Hangfire. If not, see .
15 |
16 | using System;
17 |
18 | namespace Hangfire.SqlServer
19 | {
20 | internal static class TimestampHelper
21 | {
22 | public static long GetTimestamp()
23 | {
24 | #if NETCOREAPP3_0
25 | return Environment.TickCount64;
26 | #else
27 | return Environment.TickCount;
28 | #endif
29 | }
30 |
31 | public static TimeSpan Elapsed(long timestamp)
32 | {
33 | var now = GetTimestamp();
34 | return Elapsed(now, timestamp);
35 | }
36 |
37 | public static TimeSpan Elapsed(long now, long timestamp)
38 | {
39 | #if NETCOREAPP3_0
40 | return TimeSpan.FromMilliseconds(now - timestamp);
41 | #else
42 | return TimeSpan.FromMilliseconds(unchecked((int)now - (int)timestamp));
43 | #endif
44 | }
45 | }
46 | }
--------------------------------------------------------------------------------
/src/SharedAssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.InteropServices;
3 |
4 | [assembly: AssemblyProduct("Hangfire")]
5 | [assembly: AssemblyCompany("Hangfire OÜ")]
6 | [assembly: AssemblyCopyright("Copyright © 2013-2025 Hangfire OÜ")]
7 | [assembly: AssemblyCulture("")]
8 |
9 | [assembly: ComVisible(false)]
10 |
11 | // Please don't edit it manually, use the `build.bat version` command instead.
12 | [assembly: AssemblyVersion("1.8.20")]
13 |
--------------------------------------------------------------------------------
/tests/Directory.Build.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | false
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/tests/Hangfire.Core.Tests/Common/JobLoadExceptionFacts.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Hangfire.Common;
3 | using Xunit;
4 |
5 | namespace Hangfire.Core.Tests.Common
6 | {
7 | public class JobLoadExceptionFacts
8 | {
9 | [Fact]
10 | public void Ctor_CreatesException_WithGivenMessageAnInnerException()
11 | {
12 | var innerException = new Exception();
13 | var exception = new JobLoadException("1", innerException);
14 |
15 | Assert.Equal("1", exception.Message);
16 | Assert.Same(innerException, exception.InnerException);
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/tests/Hangfire.Core.Tests/Common/MethodInfoExtensionsFacts.cs:
--------------------------------------------------------------------------------
1 | using System.Linq;
2 | using System.Reflection;
3 | using Hangfire.Common;
4 | using Xunit;
5 |
6 | namespace Hangfire.Core.Tests.Common
7 | {
8 | public class MethodInfoExtensionsFacts
9 | {
10 | [Fact]
11 | public void GetNormalizedName_ReturnsNormalizedName_ForRegularMethod()
12 | {
13 | var service = new RegularInterfaceImplementation();
14 | var normalizedName = service.GetType().GetRuntimeMethods().First().GetNormalizedName();
15 |
16 | Assert.Equal("Method", normalizedName);
17 | }
18 |
19 | [Fact]
20 | public void GetNormalizedName_ReturnsNormalizedName_ForExplicitlyImplementedMethod()
21 | {
22 | var service = new ExplicitInterfaceImplementation();
23 | var normalizedName = service.GetType().GetRuntimeMethods().First().GetNormalizedName();
24 |
25 | Assert.Equal("Method", normalizedName);
26 | }
27 |
28 | private interface IService
29 | {
30 | void Method();
31 | }
32 |
33 | private class RegularInterfaceImplementation : IService
34 | {
35 | public void Method()
36 | {
37 | }
38 | }
39 |
40 | private class ExplicitInterfaceImplementation : IService
41 | {
42 | void IService.Method()
43 | {
44 | }
45 | }
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/tests/Hangfire.Core.Tests/Common/ShallowExceptionHelperFacts.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Hangfire.Common;
3 | using Xunit;
4 |
5 | namespace Hangfire.Core.Tests.Common
6 | {
7 | public class ShallowExceptionHelperFacts
8 | {
9 | [Fact]
10 | public void PreserveOriginalStackTrace_CanBeCalledTwice_WithoutThrowingAnyException()
11 | {
12 | try
13 | {
14 | throw new InvalidOperationException("Hello, world!");
15 | }
16 | catch (Exception ex)
17 | {
18 | ex.PreserveOriginalStackTrace();
19 | ex.PreserveOriginalStackTrace();
20 | }
21 | }
22 | }
23 | }
--------------------------------------------------------------------------------
/tests/Hangfire.Core.Tests/Dashboard/BatchCommandDispatcherFacts.cs:
--------------------------------------------------------------------------------
1 | using Hangfire.Core.Tests.Stubs;
2 | using Hangfire.Dashboard;
3 | using Xunit;
4 |
5 | namespace Hangfire.Core.Tests.Dashboard
6 | {
7 | public class BatchCommandDispatcherFacts
8 | {
9 | [Fact]
10 | public void Dispatch_Sets401StatusCode_WhenNotPermitted()
11 | {
12 | var options = new DashboardOptions
13 | {
14 | IsReadOnlyFunc = _ => true
15 | };
16 | var context = new DashboardContextStub(options);
17 | var dispatcher = new BatchCommandDispatcher((DashboardContext ctx, string str) => { });
18 | dispatcher.Dispatch(context);
19 | Assert.Equal(401, context.Response.StatusCode);
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/tests/Hangfire.Core.Tests/Dashboard/CommandDispatcherFacts.cs:
--------------------------------------------------------------------------------
1 | using Hangfire.Core.Tests.Stubs;
2 | using Hangfire.Dashboard;
3 | using Xunit;
4 |
5 | namespace Hangfire.Core.Tests.Dashboard
6 | {
7 | public class CommandDispatcherFacts
8 | {
9 | [Fact]
10 | public void Dispatch_Sets401StatusCode_WhenNotPermitted()
11 | {
12 | var options = new DashboardOptions
13 | {
14 | IsReadOnlyFunc = _ => true
15 | };
16 | var context = new DashboardContextStub(options);
17 | var dispatcher = new CommandDispatcher((DashboardContext _) => false);
18 | dispatcher.Dispatch(context);
19 | Assert.Equal(401, context.Response.StatusCode);
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/tests/Hangfire.Core.Tests/Dashboard/DashboardOptionsFacts.cs:
--------------------------------------------------------------------------------
1 | using System.Linq;
2 | using Hangfire.Dashboard;
3 | using Xunit;
4 |
5 | namespace Hangfire.Core.Tests.Dashboard
6 | {
7 | public class DashboardOptionsFacts
8 | {
9 | [Fact]
10 | public void Ctor_SetsDefaultValues_ForAllOptions()
11 | {
12 | var options = new DashboardOptions();
13 | Assert.Equal("/", options.AppPath);
14 | Assert.Equal("", options.PrefixPath);
15 | Assert.NotNull(options.Authorization);
16 | Assert.IsType(options.Authorization.FirstOrDefault());
17 | Assert.Equal(2000, options.StatsPollingInterval);
18 | Assert.True(options.DisplayStorageConnectionString);
19 | Assert.Equal("Hangfire Dashboard", options.DashboardTitle);
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/tests/Hangfire.Core.Tests/Dashboard/HtmlHelperFacts.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Hangfire.Dashboard;
3 | using Moq;
4 | using Xunit;
5 |
6 | namespace Hangfire.Core.Tests.Dashboard
7 | {
8 | public class HtmlHelperFacts
9 | {
10 | private readonly Mock _page;
11 |
12 | public HtmlHelperFacts()
13 | {
14 | _page = new Mock();
15 | }
16 |
17 | [Fact]
18 | public void ToHumanDuration_FormatsFractionalSeconds()
19 | {
20 | var helper = CreateHelper();
21 | var result = helper.ToHumanDuration(TimeSpan.FromSeconds(1.087));
22 | Assert.Equal("+1.087s", result);
23 | }
24 |
25 | private HtmlHelper CreateHelper()
26 | {
27 | return new HtmlHelper(_page.Object);
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/tests/Hangfire.Core.Tests/GlobalConfigurationExtensionsFacts.cs:
--------------------------------------------------------------------------------
1 | using Hangfire.Common;
2 | using Newtonsoft.Json;
3 | using Newtonsoft.Json.Serialization;
4 | using Xunit;
5 |
6 | namespace Hangfire.Core.Tests
7 | {
8 | public class GloabalConfigurationExtensionsFacts
9 | {
10 | [Fact, CleanSerializerSettings]
11 | public void UseSerializationSettings_AffectSerializationWithUserSettings()
12 | {
13 | GlobalConfiguration.Configuration.UseSerializerSettings(new JsonSerializerSettings
14 | {
15 | ContractResolver = new CamelCasePropertyNamesContractResolver()
16 | });
17 |
18 | var result = SerializationHelper.Serialize(new CustomClass { StringProperty = "Value" }, SerializationOption.User);
19 | Assert.Equal(@"{""stringProperty"":""Value""}", result);
20 | }
21 |
22 | [Fact, CleanSerializerSettings]
23 | public void UseSerializationSettingsWithCallback_AffectSerializationWithUserSettings()
24 | {
25 | GlobalConfiguration.Configuration.UseRecommendedSerializerSettings(settings =>
26 | {
27 | settings.ContractResolver = new CamelCasePropertyNamesContractResolver();
28 | });
29 |
30 | var result = SerializationHelper.Serialize(new CustomClass { StringProperty = "Value" }, SerializationOption.User);
31 | Assert.Equal(@"{""stringProperty"":""Value""}", result);
32 | }
33 |
34 | public class CustomClass
35 | {
36 | public string StringProperty { get; set; }
37 | }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/tests/Hangfire.Core.Tests/GlobalStateHandlersFacts.cs:
--------------------------------------------------------------------------------
1 | using System.Linq;
2 | using Hangfire.States;
3 | using Xunit;
4 |
5 | namespace Hangfire.Core.Tests
6 | {
7 | public class GlobalStateHandlersFacts
8 | {
9 | [Fact]
10 | public void AllBasicHandlersShouldBeIncluded()
11 | {
12 | var handlerTypes = GlobalStateHandlers.Handlers.Select(x => x.GetType()).ToArray();
13 |
14 | Assert.Contains(typeof(SucceededState.Handler), handlerTypes);
15 | Assert.Contains(typeof(ScheduledState.Handler), handlerTypes);
16 | Assert.Contains(typeof(EnqueuedState.Handler), handlerTypes);
17 | Assert.Contains(typeof(DeletedState.Handler), handlerTypes);
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/tests/Hangfire.Core.Tests/GlobalTestsConfiguration.cs:
--------------------------------------------------------------------------------
1 | using Xunit;
2 |
3 | [assembly: CollectionBehavior(MaxParallelThreads = 1)]
4 |
--------------------------------------------------------------------------------
/tests/Hangfire.Core.Tests/Hangfire.Core.Tests.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net452;net461;netcoreapp3.1;net6.0
5 | 0618
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 | ReferencedCronos
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/tests/Hangfire.Core.Tests/Hangfire.Core.Tests.csproj.DotSettings:
--------------------------------------------------------------------------------
1 |
2 | True
--------------------------------------------------------------------------------
/tests/Hangfire.Core.Tests/JobActivatorFacts.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Xunit;
3 |
4 | namespace Hangfire.Core.Tests
5 | {
6 | public class JobActivatorFacts
7 | {
8 | [Fact, GlobalLock]
9 | public void SetCurrent_ThrowsAnException_WhenValueIsNull()
10 | {
11 | Assert.Throws(() => JobActivator.Current = null);
12 | }
13 |
14 | [Fact, GlobalLock]
15 | public void GetCurrent_ReturnsPreviouslySetValue()
16 | {
17 | var activator = new JobActivator();
18 | JobActivator.Current = activator;
19 |
20 | Assert.Same(activator, JobActivator.Current);
21 | }
22 |
23 | [Fact]
24 | public void DefaultActivator_CanCreateInstanceOfClassWithDefaultConstructor()
25 | {
26 | var activator = new JobActivator();
27 |
28 | var instance = activator.ActivateJob(typeof (DefaultConstructor));
29 |
30 | Assert.NotNull(instance);
31 | }
32 |
33 | [Fact]
34 | public void DefaultActivator_ThrowAnException_IfThereIsNoDefaultConstructor()
35 | {
36 | var activator = new JobActivator();
37 |
38 | Assert.Throws(
39 | () => activator.ActivateJob(typeof (CustomConstructor)));
40 | }
41 |
42 | public class DefaultConstructor
43 | {
44 | }
45 |
46 | public class CustomConstructor
47 | {
48 | // ReSharper disable once UnusedParameter.Local
49 | public CustomConstructor(string arg)
50 | {
51 | }
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/tests/Hangfire.Core.Tests/JobCancellationTokenFacts.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Xunit;
3 |
4 | namespace Hangfire.Core.Tests
5 | {
6 | public class JobCancellationTokenFacts
7 | {
8 | [Fact]
9 | public void ShutdownToken_IsInCanceledState_WhenPassingTrueValue()
10 | {
11 | var token = new JobCancellationToken(true);
12 | Assert.True(token.ShutdownToken.IsCancellationRequested);
13 | }
14 |
15 | [Fact]
16 | public void ThrowIfCancellationRequested_DoesNotThrowOnFalseValue()
17 | {
18 | var token = new JobCancellationToken(false);
19 |
20 | // Does not throw
21 | token.ThrowIfCancellationRequested();
22 | }
23 |
24 | [Fact]
25 | public void ThrowIfCancellationRequested_ThrowsOnTrueValue()
26 | {
27 | var token = new JobCancellationToken(true);
28 |
29 | Assert.Throws(
30 | () => token.ThrowIfCancellationRequested());
31 | }
32 |
33 | [Fact]
34 | public void Null_ReturnsNullValue()
35 | {
36 | Assert.Null(JobCancellationToken.Null);
37 | }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/tests/Hangfire.Core.Tests/Mocks/BackgroundJobMock.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Hangfire.Common;
3 |
4 | namespace Hangfire.Core.Tests
5 | {
6 | public class BackgroundJobMock
7 | {
8 | private readonly Lazy _object;
9 |
10 | public BackgroundJobMock()
11 | {
12 | Id = "JobId";
13 | Job = Job.FromExpression(() => SomeMethod());
14 | CreatedAt = DateTime.UtcNow;
15 |
16 | _object = new Lazy(
17 | () => new BackgroundJob(Id, Job, CreatedAt));
18 | }
19 |
20 | public string Id { get; set; }
21 | public Job Job { get; set; }
22 | public DateTime CreatedAt { get; set; }
23 |
24 | public BackgroundJob Object => _object.Value;
25 |
26 | public static void SomeMethod() { }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/tests/Hangfire.Core.Tests/Mocks/BackgroundProcessContextMock.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Threading;
4 | using Hangfire.Server;
5 | using Moq;
6 |
7 | namespace Hangfire.Core.Tests
8 | {
9 | public class BackgroundProcessContextMock
10 | {
11 | private readonly Lazy _context;
12 |
13 | public BackgroundProcessContextMock()
14 | {
15 | ServerId = "server";
16 | Storage = new Mock();
17 | Properties = new Dictionary();
18 | ExecutionId = Guid.NewGuid();
19 | StoppingTokenSource = new CancellationTokenSource();
20 | StoppedTokenSource = new CancellationTokenSource();
21 | ShutdownTokenSource = new CancellationTokenSource();
22 |
23 | _context = new Lazy(
24 | () => new BackgroundProcessContext(ServerId, Storage.Object, Properties, ExecutionId,
25 | StoppingTokenSource.Token, StoppedTokenSource.Token, ShutdownTokenSource.Token));
26 | }
27 |
28 | public BackgroundProcessContext Object => _context.Value;
29 |
30 | public string ServerId { get; set; }
31 | public Mock Storage { get; set; }
32 | public IDictionary Properties { get; set; }
33 | public Guid ExecutionId { get; set; }
34 | public CancellationTokenSource StoppingTokenSource { get; set; }
35 | public CancellationTokenSource StoppedTokenSource { get; set; }
36 | public CancellationTokenSource ShutdownTokenSource { get; set; }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/tests/Hangfire.Core.Tests/Mocks/ElectStateContextMock.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Hangfire.States;
3 |
4 | namespace Hangfire.Core.Tests
5 | {
6 | public class ElectStateContextMock
7 | {
8 | private readonly Lazy _context;
9 |
10 | public ElectStateContextMock()
11 | {
12 | ApplyContext = new ApplyStateContextMock();
13 |
14 | _context = new Lazy(
15 | () => new ElectStateContext(ApplyContext.Object));
16 | }
17 |
18 | public ApplyStateContextMock ApplyContext { get; set; }
19 |
20 | public ElectStateContext Object => _context.Value;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/tests/Hangfire.Core.Tests/Mocks/PerformContextMock.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Hangfire.Server;
3 | using Hangfire.Storage;
4 | using Moq;
5 |
6 | namespace Hangfire.Core.Tests
7 | {
8 | public class PerformContextMock
9 | {
10 | private readonly Lazy _context;
11 |
12 | public PerformContextMock()
13 | {
14 | Storage = new Mock();
15 | Connection = new Mock();
16 | BackgroundJob = new BackgroundJobMock();
17 | CancellationToken = new Mock();
18 |
19 | _context = new Lazy(
20 | () => new PerformContext(Storage.Object, Connection.Object, BackgroundJob.Object, CancellationToken.Object));
21 | }
22 |
23 | public Mock Storage { get; set; }
24 | public Mock Connection { get; set; }
25 | public BackgroundJobMock BackgroundJob { get; set; }
26 | public Mock CancellationToken { get; set; }
27 |
28 | public PerformContext Object => _context.Value;
29 |
30 | public static void SomeMethod()
31 | {
32 | }
33 |
34 | public PerformingContext GetPerformingContext()
35 | {
36 | return new PerformingContext(Object);
37 | }
38 |
39 | public PerformedContext GetPerformedContext(object result = null, bool canceled = false, Exception exception = null)
40 | {
41 | return new PerformedContext(Object, result, canceled, exception);
42 | }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/tests/Hangfire.Core.Tests/QueueAttributeFacts.cs:
--------------------------------------------------------------------------------
1 | using Hangfire.States;
2 | using Moq;
3 | using Xunit;
4 |
5 | namespace Hangfire.Core.Tests
6 | {
7 | public class QueueAttributeFacts
8 | {
9 | private readonly ElectStateContextMock _context;
10 |
11 | public QueueAttributeFacts()
12 | {
13 | _context = new ElectStateContextMock
14 | {
15 | ApplyContext = { NewStateObject = new EnqueuedState("queue") }
16 | };
17 | }
18 |
19 | [Fact]
20 | public void Ctor_CorrectlySets_AllPropertyValues()
21 | {
22 | var filter = new QueueAttribute("hello");
23 | Assert.Equal("hello", filter.Queue);
24 | }
25 |
26 | [Fact]
27 | public void OnStateElection_OverridesTheQueue_OfTheCandidateState()
28 | {
29 | var filter = new QueueAttribute("override");
30 | filter.OnStateElection(_context.Object);
31 |
32 | Assert.Equal("override", ((EnqueuedState)_context.Object.CandidateState).Queue);
33 | }
34 |
35 | [Fact]
36 | public void OnStateElection_DoesNotDoAnything_IfStateIsNotEnqueuedState()
37 | {
38 | var filter = new QueueAttribute("override");
39 | var context = new ElectStateContextMock
40 | {
41 | ApplyContext = { NewState = new Mock() }
42 | };
43 |
44 | // Does not throw
45 | filter.OnStateElection(context.Object);
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/tests/Hangfire.Core.Tests/RecurringJobOptionsFacts.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Xunit;
3 |
4 | // ReSharper disable AssignNullToNotNullAttribute
5 |
6 | namespace Hangfire.Core.Tests
7 | {
8 | public class RecurringJobOptionsFacts
9 | {
10 | [Fact]
11 | public void Ctor_SetTheDefaultValues_ForProperties()
12 | {
13 | var options = new RecurringJobOptions();
14 |
15 | Assert.Equal(TimeZoneInfo.Utc, options.TimeZone);
16 | Assert.Equal("default", options.QueueName);
17 | Assert.Equal(MisfireHandlingMode.Relaxed, options.MisfireHandling);
18 | }
19 |
20 | [Fact]
21 | public void SetTimeZone_ThrowsAnException_WhenValueIsNull()
22 | {
23 | var options = new RecurringJobOptions();
24 |
25 | Assert.Throws(() => options.TimeZone = null);
26 | }
27 |
28 | [Fact]
29 | public void SetQueueName_ThrowsAnException_WhenValueIsNull()
30 | {
31 | var options = new RecurringJobOptions();
32 |
33 | Assert.Throws(() => options.QueueName = null);
34 | }
35 |
36 | [Fact]
37 | public void SetQueueName_ThrowsAnException_WhenQueueNameHasInvalidFormat()
38 | {
39 | var options = new RecurringJobOptions();
40 |
41 | var exception = Assert.Throws(
42 | () => options.QueueName = "UPPER_CASE");
43 |
44 | Assert.Equal("value", exception.ParamName);
45 | }
46 | }
47 | }
--------------------------------------------------------------------------------
/tests/Hangfire.Core.Tests/Server/ServerWatchdogFacts.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Threading;
3 | using Hangfire.Server;
4 | using Hangfire.Storage;
5 | using Moq;
6 | using Xunit;
7 |
8 | namespace Hangfire.Core.Tests.Server
9 | {
10 | public class ServerWatchdogFacts
11 | {
12 | private readonly Mock _connection;
13 | private readonly BackgroundProcessContextMock _context;
14 | private readonly TimeSpan _checkInterval;
15 | private readonly TimeSpan _serverTimeout;
16 |
17 | public ServerWatchdogFacts()
18 | {
19 | _checkInterval = Timeout.InfiniteTimeSpan;
20 | _serverTimeout = TimeSpan.FromSeconds(5);
21 |
22 | _context = new BackgroundProcessContextMock();
23 | _context.StoppingTokenSource.Cancel();
24 |
25 | _connection = new Mock();
26 | _context.Storage.Setup(x => x.GetConnection()).Returns(_connection.Object);
27 | }
28 |
29 | [Fact]
30 | public void Execute_DelegatesRemovalToStorageConnection()
31 | {
32 | _connection.Setup(x => x.RemoveTimedOutServers(It.IsAny())).Returns(1);
33 | var watchdog = new ServerWatchdog(_checkInterval, _serverTimeout);
34 |
35 | Assert.Throws(() => watchdog.Execute(_context.Object));
36 |
37 | _connection.Verify(x => x.RemoveTimedOutServers(_serverTimeout));
38 | _connection.Verify(x => x.Dispose(), Times.Once);
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/tests/Hangfire.Core.Tests/States/AwaitingStateHandlerFacts.cs:
--------------------------------------------------------------------------------
1 | using Hangfire.States;
2 | using Hangfire.Storage;
3 | using Moq;
4 | using Xunit;
5 |
6 | namespace Hangfire.Core.Tests.States
7 | {
8 | public class AwaitingStateHandlerFacts
9 | {
10 | private readonly ApplyStateContextMock _context;
11 | private readonly Mock _transactionMock
12 | = new Mock();
13 |
14 | public AwaitingStateHandlerFacts()
15 | {
16 | _context = new ApplyStateContextMock();
17 | }
18 |
19 | [Fact]
20 | public void ShouldWorkOnlyWithAwaitingState()
21 | {
22 | var handler = new AwaitingState.Handler();
23 | Assert.Equal(AwaitingState.StateName, handler.StateName);
24 | }
25 |
26 | [Fact]
27 | public void Apply_ShouldAddToSet_Awaiting()
28 | {
29 | var handler = new AwaitingState.Handler();
30 | handler.Apply(_context.Object, _transactionMock.Object);
31 |
32 | _transactionMock.Verify(x => x.AddToSet("awaiting", "JobId", It.IsAny()), Times.Once);
33 | }
34 |
35 | [Fact]
36 | public void Unapply_ShouldRemoveFromSet_Awaiting()
37 | {
38 | var handler = new AwaitingState.Handler();
39 | handler.Unapply(_context.Object, _transactionMock.Object);
40 |
41 | _transactionMock.Verify(x => x.RemoveFromSet("awaiting", "JobId"), Times.Once);
42 | }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/tests/Hangfire.Core.Tests/States/DeletedStateHandlerFacts.cs:
--------------------------------------------------------------------------------
1 | using Hangfire.States;
2 | using Hangfire.Storage;
3 | using Moq;
4 | using Xunit;
5 |
6 | namespace Hangfire.Core.Tests.States
7 | {
8 | public class DeletedStateHandlerFacts
9 | {
10 | private readonly ApplyStateContextMock _context;
11 | private readonly Mock _transactionMock
12 | = new Mock();
13 |
14 | public DeletedStateHandlerFacts()
15 | {
16 | _context = new ApplyStateContextMock();
17 | }
18 |
19 | [Fact]
20 | public void ShouldWorkOnlyWithDeletedState()
21 | {
22 | var handler = new DeletedState.Handler();
23 | Assert.Equal(DeletedState.StateName, handler.StateName);
24 | }
25 |
26 | [Fact]
27 | public void Apply_ShouldIncrease_DeletedCounter()
28 | {
29 | var handler = new DeletedState.Handler();
30 | handler.Apply(_context.Object, _transactionMock.Object);
31 |
32 | _transactionMock.Verify(x => x.IncrementCounter("stats:deleted"), Times.Once);
33 | }
34 |
35 | [Fact]
36 | public void Unapply_ShouldDecrementStatistics()
37 | {
38 | var handler = new DeletedState.Handler();
39 | handler.Unapply(_context.Object, _transactionMock.Object);
40 |
41 | _transactionMock.Verify(x => x.DecrementCounter("stats:deleted"), Times.Once);
42 | }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/tests/Hangfire.Core.Tests/States/SucceededStateHandlerFacts.cs:
--------------------------------------------------------------------------------
1 | using Hangfire.States;
2 | using Hangfire.Storage;
3 | using Moq;
4 | using Xunit;
5 |
6 | namespace Hangfire.Core.Tests.States
7 | {
8 | public class SucceededStateHandlerFacts
9 | {
10 | private readonly ApplyStateContextMock _context;
11 | private readonly Mock _transactionMock
12 | = new Mock();
13 |
14 | public SucceededStateHandlerFacts()
15 | {
16 | _context = new ApplyStateContextMock();
17 | }
18 |
19 | [Fact]
20 | public void ShouldWorkOnlyWithSucceededState()
21 | {
22 | var handler = new SucceededState.Handler();
23 | Assert.Equal(SucceededState.StateName, handler.StateName);
24 | }
25 |
26 | [Fact]
27 | public void Apply_ShouldIncrease_SucceededCounter()
28 | {
29 | var handler = new SucceededState.Handler();
30 | handler.Apply(_context.Object, _transactionMock.Object);
31 |
32 | _transactionMock.Verify(x => x.IncrementCounter("stats:succeeded"), Times.Once);
33 | }
34 |
35 | [Fact]
36 | public void Unapply_ShouldDecrementStatistics()
37 | {
38 | var handler = new SucceededState.Handler();
39 | handler.Unapply(_context.Object, _transactionMock.Object);
40 |
41 | _transactionMock.Verify(x => x.DecrementCounter("stats:succeeded"), Times.Once);
42 | }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/tests/Hangfire.Core.Tests/Storage/MonitoringTypeFacts.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using Hangfire.Storage.Monitoring;
3 | using Xunit;
4 |
5 | namespace Hangfire.Core.Tests.Storage
6 | {
7 | public class MonitoringTypeFacts
8 | {
9 | [Fact]
10 | public void EnqueuedJobDto_Ctor_SetsInEnqueuedState()
11 | {
12 | Assert.True(new EnqueuedJobDto().InEnqueuedState);
13 | }
14 |
15 | [Fact]
16 | public void FailedJobDto_Ctor_SetsInFailedState()
17 | {
18 | Assert.True(new FailedJobDto().InFailedState);
19 | }
20 |
21 | [Fact]
22 | public void ProcessingJobDto_Ctor_SetsInProcessingState()
23 | {
24 | Assert.True(new ProcessingJobDto().InProcessingState);
25 | }
26 |
27 | [Fact]
28 | public void ScheduledJobDto_Ctor_SetsInScheduledState()
29 | {
30 | Assert.True(new ScheduledJobDto().InScheduledState);
31 | }
32 |
33 | [Fact]
34 | public void SucceededJobDto_Ctor_SetsInSucceededState()
35 | {
36 | Assert.True(new SucceededJobDto().InSucceededState);
37 | }
38 |
39 | [Fact]
40 | public void DeletedJobDto_Ctor_SetsInDeletedState()
41 | {
42 | Assert.True(new DeletedJobDto().InDeletedState);
43 | }
44 |
45 | [Fact]
46 | public void JobList_Ctor_ShouldInitializeCollection()
47 | {
48 | var list = new JobList(new Dictionary { { "1", 2 } });
49 | Assert.Single(list);
50 | }
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/tests/Hangfire.Core.Tests/Stubs/DashboardContextStub.cs:
--------------------------------------------------------------------------------
1 | using Hangfire.Dashboard;
2 |
3 | namespace Hangfire.Core.Tests.Stubs
4 | {
5 | class DashboardContextStub : DashboardContext
6 | {
7 | public DashboardContextStub(DashboardOptions options) : base(new JobStorageStub(), options)
8 | {
9 | Response = new DashboardResponseStub();
10 | }
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/tests/Hangfire.Core.Tests/Stubs/DashboardResponseStub.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 | using System.Threading.Tasks;
4 | using Hangfire.Dashboard;
5 |
6 | namespace Hangfire.Core.Tests.Stubs
7 | {
8 | class DashboardResponseStub : DashboardResponse
9 | {
10 | public override string ContentType { get; set; }
11 | public override int StatusCode { get; set; }
12 | public override Stream Body { get; }
13 | public override void SetExpire(DateTimeOffset? value)
14 | {
15 | throw new NotImplementedException();
16 | }
17 |
18 | public override Task WriteAsync(string text)
19 | {
20 | throw new NotImplementedException();
21 | }
22 | }
23 | }
--------------------------------------------------------------------------------
/tests/Hangfire.Core.Tests/Stubs/JobStorageStub.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Hangfire.Storage;
3 |
4 | namespace Hangfire.Core.Tests.Stubs
5 | {
6 | class JobStorageStub : JobStorage
7 | {
8 | public override IMonitoringApi GetMonitoringApi()
9 | {
10 | throw new NotImplementedException();
11 | }
12 |
13 | public override IStorageConnection GetConnection()
14 | {
15 | throw new NotImplementedException();
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/tests/Hangfire.Core.Tests/Utils/CleanSerializerSettingsAttribute.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using Hangfire.Common;
3 | using Newtonsoft.Json;
4 | using Xunit.Sdk;
5 |
6 | namespace Hangfire.Core.Tests
7 | {
8 | internal sealed class CleanSerializerSettingsAttribute : BeforeAfterTestAttribute
9 | {
10 | public override void Before(MethodInfo methodUnderTest)
11 | {
12 | ClearSettings();
13 | }
14 |
15 | public override void After(MethodInfo methodUnderTest)
16 | {
17 | ClearSettings();
18 | }
19 |
20 | private static void ClearSettings()
21 | {
22 | #pragma warning disable 618
23 | JobHelper.SetSerializerSettings(null);
24 | #pragma warning restore 618
25 | SerializationHelper.SetUserSerializerSettings(null);
26 | #if !NET452 && !NET461
27 | JsonConvert.DefaultSettings = null;
28 | #endif
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/tests/Hangfire.Core.Tests/Utils/CultureHelper.cs:
--------------------------------------------------------------------------------
1 | using System.Globalization;
2 | using System.Threading;
3 |
4 | namespace Hangfire.Core.Tests
5 | {
6 | internal static class CultureHelper
7 | {
8 | public static void SetCurrentCulture(CultureInfo cultureInfo)
9 | {
10 | #if !NETCOREAPP1_0
11 | Thread.CurrentThread.CurrentCulture = cultureInfo;
12 | #else
13 | CultureInfo.CurrentCulture = cultureInfo;
14 | #endif
15 | }
16 |
17 | public static void SetCurrentUICulture(CultureInfo cultureInfo)
18 | {
19 | #if !NETCOREAPP1_0
20 | Thread.CurrentThread.CurrentUICulture = cultureInfo;
21 | #else
22 | CultureInfo.CurrentUICulture = cultureInfo;
23 | #endif
24 | }
25 |
26 | public static void SetCurrentCulture(string id)
27 | {
28 | #if !NETCOREAPP1_0
29 | Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo(id);
30 | #else
31 | CultureInfo.CurrentCulture = new CultureInfo(id);
32 | #endif
33 | }
34 |
35 | public static void SetCurrentUICulture(string id)
36 | {
37 | #if !NETCOREAPP1_0
38 | Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(id);
39 | #else
40 | CultureInfo.CurrentUICulture = new CultureInfo(id);
41 | #endif
42 | }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/tests/Hangfire.Core.Tests/Utils/DataCompatibilityRangeFactAttribute.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Linq;
3 | using Xunit;
4 | using Xunit.Sdk;
5 |
6 | namespace Hangfire.Core.Tests
7 | {
8 | [XunitTestCaseDiscoverer("Hangfire.Core.Tests.DataCompatibilityRangeFactDiscoverer", "Hangfire.Core.Tests")]
9 | [AttributeUsage(AttributeTargets.Method)]
10 | internal sealed class DataCompatibilityRangeFactAttribute : FactAttribute
11 | {
12 | internal static readonly CompatibilityLevel PossibleMinLevel;
13 | internal static readonly CompatibilityLevel PossibleMaxExcludingLevel;
14 |
15 | static DataCompatibilityRangeFactAttribute()
16 | {
17 | var compatibilityLevels = Enum.GetValues(typeof(CompatibilityLevel))
18 | .Cast()
19 | .ToArray();
20 |
21 | PossibleMinLevel = compatibilityLevels.Min();
22 | PossibleMaxExcludingLevel = compatibilityLevels.Max() + 1;
23 | }
24 |
25 | public DataCompatibilityRangeFactAttribute()
26 | {
27 | MinLevel = PossibleMinLevel;
28 | MaxExcludingLevel = PossibleMaxExcludingLevel;
29 | }
30 |
31 | public CompatibilityLevel MinLevel { get; set; }
32 | public CompatibilityLevel MaxExcludingLevel { get; set; }
33 | }
34 | }
--------------------------------------------------------------------------------
/tests/Hangfire.Core.Tests/Utils/DataCompatibilityRangeTestCase.cs:
--------------------------------------------------------------------------------
1 | using System.Threading;
2 | using System.Threading.Tasks;
3 | using Xunit.Abstractions;
4 | using Xunit.Sdk;
5 |
6 | namespace Hangfire.Core.Tests
7 | {
8 | internal sealed class DataCompatibilityRangeTestCase : XunitTestCase
9 | {
10 | #pragma warning disable 618
11 | public DataCompatibilityRangeTestCase()
12 | #pragma warning restore 618
13 | {
14 | }
15 |
16 | public DataCompatibilityRangeTestCase(
17 | IMessageSink diagnosticMessageSink,
18 | TestMethodDisplay defaultMethodDisplay,
19 | ITestMethod testMethod,
20 | object[] testMethodArguments)
21 | : base(diagnosticMessageSink, defaultMethodDisplay, testMethod, testMethodArguments)
22 | {
23 | }
24 |
25 | public override Task RunAsync(
26 | IMessageSink diagnosticMessageSink,
27 | IMessageBus messageBus,
28 | object[] constructorArguments,
29 | ExceptionAggregator aggregator,
30 | CancellationTokenSource cancellationTokenSource)
31 | {
32 | return new DataCompatibilityRangeTestCaseRunner(
33 | this,
34 | DisplayName,
35 | SkipReason,
36 | constructorArguments,
37 | TestMethodArguments,
38 | messageBus,
39 | aggregator,
40 | cancellationTokenSource)
41 | .RunAsync();
42 | }
43 | }
44 | }
--------------------------------------------------------------------------------
/tests/Hangfire.Core.Tests/Utils/DataCompatibilityRangeTestCaseRunner.cs:
--------------------------------------------------------------------------------
1 | using System.Threading;
2 | using System.Threading.Tasks;
3 | using Xunit.Sdk;
4 |
5 | namespace Hangfire.Core.Tests
6 | {
7 | internal sealed class DataCompatibilityRangeTestCaseRunner : XunitTestCaseRunner
8 | {
9 | public DataCompatibilityRangeTestCaseRunner(
10 | IXunitTestCase testCase,
11 | string displayName,
12 | string skipReason,
13 | object[] constructorArguments,
14 | object[] testMethodArguments,
15 | IMessageBus messageBus,
16 | ExceptionAggregator aggregator,
17 | CancellationTokenSource cancellationTokenSource)
18 | : base(testCase, displayName, skipReason, constructorArguments, testMethodArguments, messageBus, aggregator,
19 | cancellationTokenSource)
20 | {
21 | }
22 |
23 | protected override Task RunTestAsync()
24 | {
25 | return new DataCompatibilityRangeTestRunner(new XunitTest(TestCase, DisplayName), MessageBus, TestClass, ConstructorArguments, TestMethod, TestMethodArguments, SkipReason, BeforeAfterAttributes, new ExceptionAggregator(Aggregator), CancellationTokenSource)
26 | .RunAsync();
27 | }
28 | }
29 | }
--------------------------------------------------------------------------------
/tests/Hangfire.Core.Tests/Utils/DataCompatibilityRangeTheoryAttribute.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Xunit;
3 | using Xunit.Sdk;
4 |
5 | namespace Hangfire.Core.Tests
6 | {
7 | [XunitTestCaseDiscoverer("Hangfire.Core.Tests.DataCompatibilityRangeTheoryDiscoverer", "Hangfire.Core.Tests")]
8 | [AttributeUsage(AttributeTargets.Method)]
9 | internal sealed class DataCompatibilityRangeTheoryAttribute : TheoryAttribute
10 | {
11 | public DataCompatibilityRangeTheoryAttribute()
12 | {
13 | MinLevel = DataCompatibilityRangeFactAttribute.PossibleMinLevel;
14 | MaxExcludingLevel = DataCompatibilityRangeFactAttribute.PossibleMaxExcludingLevel;
15 | }
16 |
17 | public CompatibilityLevel MinLevel { get; set; }
18 | public CompatibilityLevel MaxExcludingLevel { get; set; }
19 | }
20 | }
--------------------------------------------------------------------------------
/tests/Hangfire.Core.Tests/Utils/DataCompatibilityRangeTheoryTestCase.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Threading;
3 | using System.Threading.Tasks;
4 | using Hangfire.Annotations;
5 | using Xunit.Abstractions;
6 | using Xunit.Sdk;
7 |
8 | namespace Hangfire.Core.Tests
9 | {
10 | internal sealed class DataCompatibilityRangeTheoryTestCase : XunitTestCase
11 | {
12 | [Obsolete("Called by the de-serializer; should only be called by deriving classes for de-serialization purposes")]
13 | [UsedImplicitly]
14 | public DataCompatibilityRangeTheoryTestCase()
15 | {
16 | }
17 |
18 | public DataCompatibilityRangeTheoryTestCase(
19 | CompatibilityLevel compatibilityLevel,
20 | IMessageSink diagnosticMessageSink,
21 | TestMethodDisplay defaultMethodDisplay,
22 | ITestMethod testMethod)
23 | : base(diagnosticMessageSink, defaultMethodDisplay, testMethod, new object[] { compatibilityLevel })
24 | {
25 | }
26 |
27 | public override Task RunAsync(
28 | IMessageSink diagnosticMessageSink,
29 | IMessageBus messageBus,
30 | object[] constructorArguments,
31 | ExceptionAggregator aggregator,
32 | CancellationTokenSource cancellationTokenSource)
33 | {
34 | return new DataCompatibilityRangeTheoryTestCaseRunner(this, DisplayName, SkipReason, constructorArguments, TestMethodArguments, diagnosticMessageSink, messageBus, aggregator, cancellationTokenSource).RunAsync();
35 | }
36 | }
37 | }
--------------------------------------------------------------------------------
/tests/Hangfire.Core.Tests/Utils/GlobalLockAttribute.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Threading;
3 | using Xunit.Sdk;
4 |
5 | namespace Hangfire.Core.Tests
6 | {
7 | internal sealed class GlobalLockAttribute : BeforeAfterTestAttribute
8 | {
9 | private readonly object _globalLock = new object();
10 |
11 | public string Reason { get; set; }
12 |
13 | public override void Before(MethodInfo methodUnderTest)
14 | {
15 | Monitor.Enter(_globalLock);
16 | }
17 |
18 | public override void After(MethodInfo methodUnderTest)
19 | {
20 | Monitor.Exit(_globalLock);
21 | }
22 | }
23 | }
--------------------------------------------------------------------------------
/tests/Hangfire.Core.Tests/Utils/PlatformHelper.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | #if NETCOREAPP1_0
4 | using System.Runtime.InteropServices;
5 | #endif
6 |
7 | namespace Hangfire.Core.Tests
8 | {
9 | internal static class PlatformHelper
10 | {
11 | public static bool IsRunningOnWindows()
12 | {
13 | #if !NETCOREAPP1_0
14 | return Environment.OSVersion.Platform == PlatformID.Win32NT;
15 | #else
16 | return RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
17 | #endif
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/tests/Hangfire.Core.Tests/Utils/SequenceAttribute.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Reflection;
3 | using Moq.Sequences;
4 | using Xunit;
5 | using Xunit.Sdk;
6 |
7 | namespace Hangfire.Core.Tests
8 | {
9 | public class SequenceAttribute : BeforeAfterTestAttribute
10 | {
11 | private IDisposable _sequence;
12 |
13 | public override void Before(MethodInfo methodUnderTest)
14 | {
15 | _sequence = Sequence.Create();
16 | }
17 |
18 | public override void After(MethodInfo methodUnderTest)
19 | {
20 | _sequence.Dispose();
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/tests/Hangfire.Core.Tests/Utils/SerializerSettingsHelper.cs:
--------------------------------------------------------------------------------
1 | using System.Runtime.Serialization.Formatters;
2 | using Newtonsoft.Json;
3 |
4 | namespace Hangfire.Core.Tests
5 | {
6 | public static class SerializerSettingsHelper
7 | {
8 | public static JsonSerializerSettings DangerousSettings = new JsonSerializerSettings
9 | {
10 | TypeNameHandling = TypeNameHandling.All,
11 | TypeNameAssemblyFormat = FormatterAssemblyStyle.Full,
12 |
13 | DateFormatHandling = DateFormatHandling.MicrosoftDateFormat,
14 |
15 | Formatting = Formatting.Indented,
16 |
17 | NullValueHandling = NullValueHandling.Ignore,
18 | DefaultValueHandling = DefaultValueHandling.Ignore,
19 | };
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/tests/Hangfire.Core.Tests/Utils/StaticLockAttribute.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Concurrent;
3 | using System.Reflection;
4 | using System.Threading;
5 | using Xunit.Sdk;
6 |
7 | namespace Hangfire.Core.Tests
8 | {
9 | internal sealed class StaticLockAttribute : BeforeAfterTestAttribute
10 | {
11 | private readonly ConcurrentDictionary _locks
12 | = new ConcurrentDictionary();
13 |
14 | public override void Before(MethodInfo methodUnderTest)
15 | {
16 | var type = GetType(methodUnderTest);
17 | _locks.TryAdd(type, new object());
18 |
19 | Monitor.Enter(_locks[type]);
20 | }
21 |
22 | public override void After(MethodInfo methodUnderTest)
23 | {
24 | Monitor.Exit(_locks[GetType(methodUnderTest)]);
25 | }
26 |
27 | private static Type GetType(MethodInfo methodInfo)
28 | {
29 | return methodInfo.DeclaringType;
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/tests/Hangfire.SqlServer.Msmq.Tests/Hangfire.SqlServer.Msmq.Tests.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net452
5 | 0618
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/tests/Hangfire.SqlServer.Msmq.Tests/MessageQueueExtensionsFacts.cs:
--------------------------------------------------------------------------------
1 | using MQTools;
2 | using Xunit;
3 |
4 | namespace Hangfire.SqlServer.Msmq.Tests
5 | {
6 | public class MessageQueueExtensionsFacts
7 | {
8 | [Theory]
9 | [InlineData(@"ComputerName\Private$\QueueName", "ComputerName", "Private$", "QueueName")]
10 | [InlineData(@"ComputerName\QueueName", "ComputerName", "", "QueueName")]
11 | [InlineData(@".\Private$\QueueName", ".", "Private$", "QueueName")]
12 | [InlineData(@".\QueueName", ".", "", "QueueName")]
13 | [InlineData(@"FormatName:Direct=OS:ComputerName\QueueName", "ComputerName", "", "QueueName")]
14 | [InlineData(@"FormatName:Direct=OS:ComputerName\Private$\QueueName", "ComputerName", "Private$", "QueueName")]
15 | public void QueueRegex_CorrectlyParsesPublicAndPrivateQueuePaths(
16 | string queuePath,
17 | string expectedComputerName,
18 | string expectedQueueType,
19 | string expectedQueueName)
20 | {
21 | var match = MessageQueueExtensions.GetQueuePathMatch(queuePath);
22 |
23 | Assert.NotNull(match);
24 | Assert.Equal(expectedComputerName, match.Groups["computerName"].Value);
25 | Assert.Equal(expectedQueueType, match.Groups["queueType"].Value);
26 | Assert.Equal(expectedQueueName, match.Groups["queue"].Value);
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/tests/Hangfire.SqlServer.Msmq.Tests/MsmqJobQueueProviderFacts.cs:
--------------------------------------------------------------------------------
1 | using Xunit;
2 |
3 | namespace Hangfire.SqlServer.Msmq.Tests
4 | {
5 | public class MsmqJobQueueProviderFacts
6 | {
7 | private static readonly string[] Queues = { "default" };
8 |
9 | [Fact]
10 | public void GetJobQueue_ReturnsNonNullInstance()
11 | {
12 | var provider = CreateProvider();
13 |
14 | var jobQueue = provider.GetJobQueue();
15 |
16 | Assert.NotNull(jobQueue);
17 | }
18 |
19 | [Fact]
20 | public void GetMonitoringApi_ReturnsNonNullInstance()
21 | {
22 | var provider = CreateProvider();
23 |
24 | var monitoring = provider.GetJobQueueMonitoringApi();
25 |
26 | Assert.NotNull(monitoring);
27 | }
28 |
29 | private static MsmqJobQueueProvider CreateProvider()
30 | {
31 | return new MsmqJobQueueProvider(
32 | CleanMsmqQueueAttribute.PathPattern,
33 | Queues,
34 | MsmqTransactionType.Internal);
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/tests/Hangfire.SqlServer.Msmq.Tests/MsmqSqlServerStorageExtensionsFacts.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Linq;
3 | using Xunit;
4 |
5 | // ReSharper disable AssignNullToNotNullAttribute
6 |
7 | namespace Hangfire.SqlServer.Msmq.Tests
8 | {
9 | public class MsmqSqlServerStorageExtensionsFacts
10 | {
11 | private readonly SqlServerStorage _storage;
12 |
13 | public MsmqSqlServerStorageExtensionsFacts()
14 | {
15 | _storage = new SqlServerStorage(
16 | @"Server=.\sqlexpress;Database=TheDatabase;Trusted_Connection=True;",
17 | new SqlServerStorageOptions { PrepareSchemaIfNecessary = false });
18 | }
19 |
20 | [Fact]
21 | public void UseMsmqQueues_ThrowsAnException_WhenStorageIsNull()
22 | {
23 | var exception = Assert.Throws(
24 | () => MsmqSqlServerStorageExtensions.UseMsmqQueues(null, CleanMsmqQueueAttribute.PathPattern));
25 |
26 | Assert.Equal("storage", exception.ParamName);
27 | }
28 |
29 | [Fact]
30 | public void UseMsmqQueues_AddsMsmqJobQueueProvider()
31 | {
32 | _storage.UseMsmqQueues(CleanMsmqQueueAttribute.PathPattern);
33 |
34 | var providerTypes = _storage.QueueProviders.Select(x => x.GetType());
35 | Assert.Contains(typeof(MsmqJobQueueProvider), providerTypes);
36 | }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/tests/Hangfire.SqlServer.Msmq.Tests/Utils/MsmqUtils.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Messaging;
3 |
4 | // ReSharper disable PossibleNullReferenceException
5 |
6 | namespace Hangfire.SqlServer.Msmq.Tests
7 | {
8 | internal sealed class MsmqUtils
9 | {
10 | public static void EnqueueJobId(string queue, string jobId)
11 | {
12 | using (var messageQueue = CleanMsmqQueueAttribute.GetMessageQueue(queue))
13 | using (var message = new Message { Body = jobId, Label = jobId, Formatter = new BinaryMessageFormatter() })
14 | using (var transaction = new MessageQueueTransaction())
15 | {
16 | transaction.Begin();
17 | messageQueue.Send(message, transaction);
18 | transaction.Commit();
19 | }
20 | }
21 |
22 | public static string DequeueJobId(string queue, TimeSpan timeout)
23 | {
24 | using (var messageQueue = CleanMsmqQueueAttribute.GetMessageQueue(queue))
25 | using (var transaction = new MessageQueueTransaction())
26 | {
27 | transaction.Begin();
28 |
29 | using (var message = messageQueue.Receive(timeout, transaction))
30 | {
31 | message.Formatter = new BinaryMessageFormatter();
32 | transaction.Commit();
33 |
34 | return (string)message.Body;
35 | }
36 | }
37 | }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/tests/Hangfire.SqlServer.Tests/GlobalTestsConfiguration.cs:
--------------------------------------------------------------------------------
1 | using Xunit;
2 |
3 | [assembly: CollectionBehavior(MaxParallelThreads = 1)]
4 |
--------------------------------------------------------------------------------
/tests/Hangfire.SqlServer.Tests/SqlServerMonitoringApiFacts.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Hangfire.Common;
3 | using Hangfire.SqlServer.Entities;
4 | using Xunit;
5 |
6 | namespace Hangfire.SqlServer.Tests
7 | {
8 | public class SqlServerMonitoringApiFacts
9 | {
10 | [Fact, CleanSerializerSettings]
11 | public void HandlesChangingProcessOfServerDataSerialization()
12 | {
13 | GlobalConfiguration.Configuration.UseSerializerSettings(SerializerSettingsHelper.DangerousSettings);
14 |
15 | var serverData = new ServerData
16 | {
17 | WorkerCount = 5,
18 | Queues = new[] { "default", "critical" },
19 | StartedAt = new DateTime(2016, 12, 01, 14, 33, 00)
20 | };
21 | var serializedServerData = SerializationHelper.Serialize(serverData, SerializationOption.User);
22 |
23 | var deserializedServerData = SerializationHelper.Deserialize(serializedServerData);
24 |
25 | Assert.Equal(5, deserializedServerData.WorkerCount);
26 | Assert.Equal(new[] { "default", "critical" }, deserializedServerData.Queues);
27 | Assert.Equal(new DateTime(2016, 12, 01, 14, 33, 00), deserializedServerData.StartedAt);
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/tests/Hangfire.SqlServer.Tests/StorageOptionsFacts.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Xunit;
3 |
4 | namespace Hangfire.SqlServer.Tests
5 | {
6 | public class StorageOptionsFacts
7 | {
8 | [Fact]
9 | public void Ctor_SetsTheDefaultOptions()
10 | {
11 | var options = new SqlServerStorageOptions();
12 |
13 | Assert.True(options.QueuePollInterval == TimeSpan.Zero);
14 | #pragma warning disable 618
15 | Assert.True(options.InvisibilityTimeout > TimeSpan.Zero);
16 | #pragma warning restore 618
17 | Assert.True(options.JobExpirationCheckInterval > TimeSpan.Zero);
18 | Assert.True(options.PrepareSchemaIfNecessary);
19 | }
20 |
21 | [Fact]
22 | public void Set_QueuePollInterval_DoesNotThrow_WhenGivenIntervalIsEqualToZero()
23 | {
24 | var options = new SqlServerStorageOptions();
25 | options.QueuePollInterval = TimeSpan.Zero;
26 | }
27 |
28 | [Fact]
29 | public void Set_QueuePollInterval_ShouldThrowAnException_WhenGivenIntervalIsNegative()
30 | {
31 | var options = new SqlServerStorageOptions();
32 | Assert.Throws(
33 | () => options.QueuePollInterval = TimeSpan.FromSeconds(-1));
34 | }
35 |
36 | [Fact]
37 | public void Set_QueuePollInterval_SetsTheValue()
38 | {
39 | var options = new SqlServerStorageOptions { QueuePollInterval = TimeSpan.FromSeconds(1) };
40 | Assert.Equal(TimeSpan.FromSeconds(1), options.QueuePollInterval);
41 | }
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/tests/Hangfire.SqlServer.Tests/Utils/CleanSerializerSettingsAttribute.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using Hangfire.Common;
3 | using Newtonsoft.Json;
4 | using Xunit.Sdk;
5 |
6 | namespace Hangfire.SqlServer.Tests
7 | {
8 | internal sealed class CleanSerializerSettingsAttribute : BeforeAfterTestAttribute
9 | {
10 | public override void Before(MethodInfo methodUnderTest)
11 | {
12 | ClearSettings();
13 | }
14 |
15 | public override void After(MethodInfo methodUnderTest)
16 | {
17 | ClearSettings();
18 | }
19 |
20 | private static void ClearSettings()
21 | {
22 | #pragma warning disable 618
23 | JobHelper.SetSerializerSettings(null);
24 | #pragma warning restore 618
25 | GlobalConfiguration.Configuration.UseSerializerSettings(null);
26 | #if !NET452 && !NET461
27 | JsonConvert.DefaultSettings = null;
28 | #endif
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/tests/Hangfire.SqlServer.Tests/Utils/SerializerSettingsHelper.cs:
--------------------------------------------------------------------------------
1 | using System.Runtime.Serialization.Formatters;
2 | using Newtonsoft.Json;
3 |
4 | namespace Hangfire.SqlServer.Tests
5 | {
6 | public static class SerializerSettingsHelper
7 | {
8 | public static JsonSerializerSettings DangerousSettings = new JsonSerializerSettings
9 | {
10 | TypeNameHandling = TypeNameHandling.All,
11 | TypeNameAssemblyFormat = FormatterAssemblyStyle.Full,
12 |
13 | DateFormatHandling = DateFormatHandling.MicrosoftDateFormat,
14 |
15 | Formatting = Formatting.Indented,
16 |
17 | NullValueHandling = NullValueHandling.Ignore,
18 | DefaultValueHandling = DefaultValueHandling.Ignore,
19 | };
20 | }
21 | }
22 |
--------------------------------------------------------------------------------