Skip to content

Commit

Permalink
Update to latest Hangfire (#392)
Browse files Browse the repository at this point in the history
  • Loading branch information
gottscj authored Apr 9, 2024
1 parent 4b35788 commit 9f658cc
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 36 deletions.
4 changes: 4 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@

## Change log

### v1.10.5
- Update to Hangfire 1.8.12
- Support for Stable API (strict) #387

### v1.10.4
- Update to Hangfire 1.8.11
- Update to MongoDB 2.24.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Description />
<Version>1.10.4</Version>
<Version>1.10.5</Version>
<Description>MongoDB storage implementation for Hangfire (background job system for ASP.NET applications).</Description>
<Copyright>Copyright © 2014-2019 Sergey Zwezdin, Martin Lobger, Jonas Gottschau</Copyright>
<Authors>Sergey Zwezdin, Martin Lobger, Jonas Gottschau</Authors>
Expand All @@ -21,8 +21,8 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="bootstrap" Version="5.3.3" />
<PackageReference Include="Hangfire.AspNetCore" Version="1.8.11" />
<PackageReference Include="Hangfire.Core" Version="1.8.11" />
<PackageReference Include="Hangfire.AspNetCore" Version="1.8.12" />
<PackageReference Include="Hangfire.Core" Version="1.8.12" />
<PackageReference Include="jquery" Version="3.7.1" />
<PackageReference Include="Mongo2Go" Version="3.1.3" />
<PackageReference Include="MongoDB.Driver" Version="2.24.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Description />
<Version>1.10.4</Version>
<Version>1.10.5</Version>
<Description>MongoDB storage implementation for Hangfire (background job system for ASP.NET applications).</Description>
<Copyright>Copyright © 2014-2019 Sergey Zwezdin, Martin Lobger, Jonas Gottschau</Copyright>
<Authors>Sergey Zwezdin, Martin Lobger, Jonas Gottschau</Authors>
Expand All @@ -21,8 +21,8 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="bootstrap" Version="5.3.3" />
<PackageReference Include="Hangfire.AspNetCore" Version="1.8.11" />
<PackageReference Include="Hangfire.Core" Version="1.8.11" />
<PackageReference Include="Hangfire.AspNetCore" Version="1.8.12" />
<PackageReference Include="Hangfire.Core" Version="1.8.12" />
<PackageReference Include="jquery" Version="3.7.1" />
<PackageReference Include="MongoDB.Driver" Version="2.24.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="2.2.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<AssemblyName>Hangfire.Mongo.Sample.NETCore</AssemblyName>
<OutputType>Exe</OutputType>
<PackageId>Hangfire.Mongo.Sample.NETCore</PackageId>
<Version>1.10.4</Version>
<Version>1.10.5</Version>
<Description>MongoDB storage implementation for Hangfire (background job system for ASP.NET applications).</Description>
<Copyright>Copyright © 2014-2019 Sergey Zwezdin, Martin Lobger, Jonas Gottschau</Copyright>
<Authors>Sergey Zwezdin, Martin Lobger, Jonas Gottschau</Authors>
Expand All @@ -19,7 +19,7 @@
<ProjectReference Include="..\Hangfire.Mongo\Hangfire.Mongo.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Hangfire.Core" Version="1.8.11" />
<PackageReference Include="Hangfire.Core" Version="1.8.12" />
<PackageReference Include="Mongo2Go" Version="3.1.3" />
<PackageReference Include="MongoDB.Driver" Version="2.24.0" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Hangfire.Mongo.Tests/Hangfire.Mongo.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="EphemeralMongo6" Version="1.1.3" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="NSubstitute" Version="5.1.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.7">
Expand Down
10 changes: 5 additions & 5 deletions src/Hangfire.Mongo/Hangfire.Mongo.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<VersionPrefix>1.10.4</VersionPrefix>
<VersionPrefix>1.10.5</VersionPrefix>
<TargetFramework>netstandard2.0</TargetFramework>
<NoWarn>$(NoWarn);CS0618</NoWarn>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
Expand All @@ -21,9 +21,9 @@
<owners>Sergey Zwezdin, Jonas Gottschau</owners>
<Description>MongoDB storage implementation for Hangfire (background job system for ASP.NET applications).</Description>
<PackageTags>Hangfire AspNet OWIN MongoDB CosmosDB Long-Running Background Fire-And-Forget Delayed Recurring Tasks Jobs Scheduler Threading Queues</PackageTags>
<PackageReleaseNotes>1.10.4
- Update to Hangfire 1.8.11
- Update to MongoDB 2.24.0
<PackageReleaseNotes>1.10.5
- Update to Hangfire 1.8.12
- Support for Stable API (strict) #387
</PackageReleaseNotes>
<PackageReadmeFile>README.md</PackageReadmeFile>
<!--<PackageLicenseUrl>https://raw.githubusercontent.com/sergun/Hangfire.Mongo/master/LICENSE</PackageLicenseUrl>-->
Expand All @@ -35,7 +35,7 @@
<None Include="../../README.md" pack="true" PackagePath="." />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Hangfire.Core" Version="1.8.11" />
<PackageReference Include="Hangfire.Core" Version="1.8.12" />
<PackageReference Include="MongoDB.Driver" Version="2.24.0" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,20 @@ protected virtual void BackupCollection(IMongoDatabase database, string collecti
}
});

var version = MongoVersionHelper.GetVersion(database);
if (version < new Version(2, 6))
try
{
throw new InvalidOperationException("Hangfire.Mongo is not able to backup collections in MongoDB running a version prior to 2.6");
var version = MongoVersionHelper.GetVersion(database);
if (version < new Version(2, 6))
{
throw new InvalidOperationException("Hangfire.Mongo is not able to backup collections in MongoDB running a version prior to 2.6");
}
}
catch (Exception e)
{
throw new InvalidOperationException(
$"Hangfire.Mongo could not back up collection. Failed with message: " + e.Message);
}


var dbSource = database.GetCollection<BsonDocument>(collectionName);
var indexes = dbSource.Indexes.List().ToList().Where(idx => idx["name"] != "_id_").ToList();
Expand Down
26 changes: 19 additions & 7 deletions src/Hangfire.Mongo/MongoMonitoringApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -371,14 +371,26 @@ public override IDictionary<DateTime, long> HourlyDeletedJobs()

public virtual IReadOnlyList<string> GetQueues()
{
return _dbContext.JobGraph
.Distinct(
f => f[nameof(JobDto.Queue)],
new BsonDocument("_t", nameof(JobDto)))
.ToList()
.Where(b => !b.IsBsonNull)
.Select(b => b.AsString)
var onlyQueuesWithValue = new BsonDocument
{
["_t"] = nameof(JobDto),
[nameof(JobDto.Queue)] = new BsonDocument("$ne", BsonNull.Value)
};
var byQueue = new BsonDocument("_id", $"${nameof(JobDto.Queue)}");

var result = _dbContext.JobGraph.Aggregate<BsonDocument>(
new BsonDocument
[]
{
new("$match", onlyQueuesWithValue),
new("$group", byQueue)
})
.ToList();
var queues = result
.Select(b => b["_id"].AsString)
.OrderBy(s => s)
.ToArray();
return queues;
}

public virtual IReadOnlyList<string> GetEnqueuedJobIds(string queue, int from, int perPage)
Expand Down
31 changes: 19 additions & 12 deletions src/Hangfire.Mongo/MongoVersionHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,28 @@ internal static class MongoVersionHelper
{
public static Version GetVersion(IMongoDatabase database)
{
var command = new JsonCommand<BsonDocument>("{'buildinfo': 1}");
var serverStatus = database.RunCommand(command);
if (!serverStatus.Contains("version"))
try
{
throw new InvalidOperationException($"Could not get 'buildinfo' from database: got: " +
serverStatus.ToJson());
}
var command = new JsonCommand<BsonDocument>("{'buildinfo': 1}");
var serverStatus = database.RunCommand(command);
if (!serverStatus.Contains("version"))
{
throw new InvalidOperationException("Could not get 'buildinfo' from database: got: " +
serverStatus.ToJson());
}

var versionSplit = serverStatus["version"].AsString.Split('.');
var major = int.Parse(versionSplit[0]);
var minor = int.Parse(versionSplit[1]);
var build = int.Parse(new string(versionSplit[2].TakeWhile(Char.IsDigit).ToArray()));

return new Version(major, minor, build);
var versionSplit = serverStatus["version"].AsString.Split('.');
var major = int.Parse(versionSplit[0]);
var minor = int.Parse(versionSplit[1]);
var build = int.Parse(new string(versionSplit[2].TakeWhile(Char.IsDigit).ToArray()));

return new Version(major, minor, build);
}
catch (Exception e)
{
throw new InvalidOperationException("Could not get 'buildinfo' from database: failed with message: " +
e.Message);
}
}
}
}

0 comments on commit 9f658cc

Please sign in to comment.