Skip to content

Commit

Permalink
1.1.0 - stable
Browse files Browse the repository at this point in the history
  • Loading branch information
maitlandmarshall committed Dec 15, 2020
1 parent b932caa commit 06e42ee
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using Hangfire;
using Hangfire.MemoryStorage;
using MAD.Integration.Common.Jobs;
using Microsoft.Extensions.Hosting;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

namespace MAD.Integration.Common.Tests
{
[TestClass]
public class DisableIdenticalQueuedItemsAttributeTests
{

public static async Task SomeJob()
{
await Task.Delay(TimeSpan.FromMinutes(2));
}

[TestMethod]
public void IdenticalItemsNoParameters_IgnoresDuplicate()
{
var host = IntegrationHost.CreateDefaultBuilder()
.UseHangfire(cfg => cfg.UseMemoryStorage().UseFilter(new DisableIdenticalQueuedItemsAttribute { IncludeFailedJobs = true }))
.Build();

JobFactory.CreateRecurringJob("someJob", () => SomeJob(), Cron.Minutely());
string jobId2 = BackgroundJob.Enqueue(() => SomeJob());

Assert.IsNull(jobId2);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

namespace MAD.Integration.Common.Analytics
{
public class AppInsightsEventsFilter : JobFilterAttribute, IServerFilter, IApplyStateFilter
public class AppInsightsEventsFilter : IServerFilter, IApplyStateFilter
{
[ThreadStatic]
private static IOperationHolder<RequestTelemetry> operationHolder;
Expand Down
18 changes: 18 additions & 0 deletions MAD.Integration.Common/Jobs/JobFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,23 @@ public static void CreateRecurringJob<T>(string jobName, Expression<Func<T, Task
if (newJob.LastExecution is null)
RecurringJob.Trigger(jobName);
}

public static void CreateRecurringJob(string jobName, Expression<Func<Task>> methodCall, string cronSchedule = null)
{
cronSchedule ??= Cron.Daily(22, 30);

var connection = JobStorage.Current.GetConnection();

RecurringJob.AddOrUpdate(
recurringJobId: jobName,
methodCall: methodCall,
cronExpression: cronSchedule,
timeZone: TimeZoneInfo.Local);

RecurringJobDto newJob = connection.GetRecurringJobs(new string[] { jobName }).First();

if (newJob.LastExecution is null)
RecurringJob.Trigger(jobName);
}
}
}
8 changes: 4 additions & 4 deletions MAD.Integration.Common/MAD.Integration.Common.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFrameworks>netcoreapp3.1;net5.0</TargetFrameworks>
<OutputType>Library</OutputType>
<Authors>Maitland Marshall</Authors>
<Company>Maitland's App Development</Company>
Expand All @@ -12,9 +12,9 @@
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageTags>Hangfire, Scheduling, Jobs, Simplified</PackageTags>
<Description>Provides an IntegrationHost which allows you to build integrations using Hangfire and AspNetCore</Description>
<AssemblyVersion>1.0.8.0</AssemblyVersion>
<FileVersion>1.0.8.0</FileVersion>
<Version>1.0.8</Version>
<AssemblyVersion>1.1.0.0</AssemblyVersion>
<FileVersion>1.1.0.0</FileVersion>
<Version>1.1.0</Version>
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit 06e42ee

Please sign in to comment.