Skip to content

Commit

Permalink
V.0.7.20 (#273)
Browse files Browse the repository at this point in the history
* remove newtonsoft dependency

fixes #269

* update dependencies

* add possibility to not use capped collection

make distributed lock configurable (overridable)

* fix unit tests

* Add tracing to mongoconnection

* update version info

* fix unit tests

* minor tweak

* fix bad inheritance array

* Remove regex query

Remove regex query for recurring and scheduled optimizations.
#272

* fix unit test

* update release note and changelog

Co-authored-by: Jonas Gottschau <jlg@brandarmies.com>
  • Loading branch information
gottscj and jlg4 authored Mar 25, 2021
1 parent 742a8d2 commit 7c3ae99
Show file tree
Hide file tree
Showing 22 changed files with 493 additions and 238 deletions.
10 changes: 9 additions & 1 deletion ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@

## What's New (June. 7th. 2020)
## What's New (2021-03-23)

### v0.7.20
- Update to latest Hangfire.Core (v1.7.20)
- Update to latest Mongo drivers (v2.12.1)
- Remove Newtonsoft dependency
- Add possibility to opt out of using capped collection/tailable cursor
- Optimizations to WriteOnlyTransaction filters when filtering on unique index
- Optimizations to queries for scheduled and recurrent jobs

### v0.7.19
- Update to latest Hangfire.Core (v1.7.19)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<Description />
<Version>0.7.19</Version>
<Version>0.7.20</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 @@ -20,10 +20,10 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="bootstrap" Version="4.5.3" />
<PackageReference Include="Hangfire.AspNetCore" Version="1.7.19" />
<PackageReference Include="Hangfire.Core" Version="1.7.19" />
<PackageReference Include="Hangfire.AspNetCore" Version="1.7.20" />
<PackageReference Include="Hangfire.Core" Version="1.7.20" />
<PackageReference Include="jquery" Version="3.5.1" />
<PackageReference Include="MongoDB.Driver" Version="2.11.6" />
<PackageReference Include="MongoDB.Driver" Version="2.12.1" />
<PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="5.0.0" />
</ItemGroup>
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>0.7.19</Version>
<Version>0.7.20</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 @@ -18,7 +18,7 @@
<ProjectReference Include="..\Hangfire.Mongo\Hangfire.Mongo.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Hangfire.Core" Version="1.7.19" />
<PackageReference Include="MongoDB.Driver" Version="2.11.6" />
<PackageReference Include="Hangfire.Core" Version="1.7.20" />
<PackageReference Include="MongoDB.Driver" Version="2.12.1" />
</ItemGroup>
</Project>
11 changes: 5 additions & 6 deletions src/Hangfire.Mongo.Sample.NETCore/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@ public static void Main()
{
MigrationStrategy = new MigrateMongoMigrationStrategy(),
BackupStrategy = new NoneMongoBackupStrategy()
}
},
UseNotificationsCollection = false
};

var conventionPack = new ConventionPack {new CamelCaseElementNameConvention()};
ConventionRegistry.Register("CamelCase", conventionPack, t => true);

GlobalConfiguration.Configuration.UseLogProvider(new ColouredConsoleLogProvider());

JobStorage.Current = new MongoStorage(
Expand All @@ -37,10 +35,11 @@ public static void Main()
for (var i = 0; i < JobCount; i++)
{
var jobId = i;
BackgroundJob.Enqueue(() => Console.WriteLine($"Fire-and-forget ({jobId})"));
BackgroundJob.Enqueue(() =>
Console.WriteLine($"Fire-and-forget executed after {jobId}"));
}

Console.WriteLine($"{JobCount} job(s) has been enqued. They will be executed shortly!");
Console.WriteLine($"{JobCount} job(s) has been enqueued. They will be executed shortly!");
Console.WriteLine();
Console.WriteLine("If you close this application before they are executed, ");
Console.WriteLine("they will be executed the next time you run this sample.");
Expand Down
2 changes: 1 addition & 1 deletion src/Hangfire.Mongo.Tests/ExpirationManagerFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ private MongoExpirationManager CreateManager()

private static void Commit(HangfireDbContext connection, Action<MongoWriteOnlyTransaction> action)
{
using (MongoWriteOnlyTransaction transaction = new MongoWriteOnlyTransaction(connection))
using (var transaction = new MongoWriteOnlyTransaction(connection, new MongoStorageOptions()))
{
action(transaction);
transaction.Commit();
Expand Down
5 changes: 2 additions & 3 deletions src/Hangfire.Mongo.Tests/Hangfire.Mongo.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,10 @@
<ProjectReference Include="../Hangfire.Mongo/Hangfire.Mongo.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3" />
<PackageReference Include="Moq" Version="4.16.0" />
<PackageReference Include="Moq" Version="4.16.1" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
</ItemGroup>
<ItemGroup>
<Reference Include="System.IO.Compression" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using MongoDB.Bson;
using MongoDB.Driver;
using Moq;
using Newtonsoft.Json.Linq;
using Xunit;

namespace Hangfire.Mongo.Tests.Migration
Expand Down Expand Up @@ -66,7 +65,7 @@ public void ExecuteStep01_ValidExistingServerDto_Success()
'LastHeartbeat' : ISODate('2018-12-03T22:19:00.636Z')
}";
var originalServerDto = BsonDocument.Parse(json);
var jsonData = JObject.Parse(originalServerDto["Data"].AsString);
var document = BsonDocument.Parse(originalServerDto["Data"].AsString);
var collection = _database.GetCollection<BsonDocument>("hangfire.server");
collection.DeleteOne(new BsonDocument("_id", "test-server"));
collection.InsertOne(originalServerDto);
Expand All @@ -79,10 +78,10 @@ public void ExecuteStep01_ValidExistingServerDto_Success()
var migratedServerDto = collection.Find(new BsonDocument()).Single();
Assert.True(result, "Expected migration to be successful, reported 'false'");
Assert.Equal(originalServerDto["_id"], migratedServerDto["_id"]);
Assert.Equal(int.Parse(jsonData["WorkerCount"].Value<string>()), migratedServerDto["WorkerCount"].AsInt32);
Assert.Equal(jsonData["Queues"].ToObject<string[]>(),
Assert.Equal(document["WorkerCount"].AsInt32, migratedServerDto["WorkerCount"].AsInt32);
Assert.Equal(document["Queues"].AsBsonArray.Select(d => d.AsString).ToArray(),
migratedServerDto["Queues"].AsBsonArray.Select(d => d.AsString).ToArray());
Assert.Equal(jsonData["StartedAt"]?.ToObject<DateTime?>(), migratedServerDto["StartedAt"].ToUniversalTime());
Assert.Equal(DateTime.Parse(document["StartedAt"].AsString).ToUniversalTime(), migratedServerDto["StartedAt"].ToUniversalTime());
Assert.Equal(originalServerDto["LastHeartbeat"], migratedServerDto["LastHeartbeat"].ToUniversalTime());
}

Expand Down
71 changes: 71 additions & 0 deletions src/Hangfire.Mongo.Tests/Migration/Version19MigrationStepFacts.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
using System;
using System.Linq;
using Hangfire.Mongo.Migration;
using Hangfire.Mongo.Migration.Steps.Version19;
using Hangfire.Mongo.Tests.Utils;
using MongoDB.Bson;
using MongoDB.Driver;
using Moq;
using Xunit;

namespace Hangfire.Mongo.Tests.Migration
{
public class Version19MigrationStepFacts
{
private readonly Mock<IMongoMigrationContext> _mongoMigrationBagMock;
private readonly IMongoDatabase _database;
private readonly Random _random;
private readonly AddTypeToSetDto _addTypeToSetDto;
public Version19MigrationStepFacts()
{
var dbContext = ConnectionUtils.CreateDbContext();
_database = dbContext.Database;
_mongoMigrationBagMock = new Mock<IMongoMigrationContext>(MockBehavior.Strict);
_random = new Random();
_addTypeToSetDto = new AddTypeToSetDto();
}

[Fact]
public void ExecuteStep01_AddTypeToSetDto_Success()
{
// ARRANGE
var collection = _database.GetCollection<BsonDocument>("hangfire.jobGraph");

collection.Indexes.DropAll();
collection.InsertMany(new []
{
CreateSetDto(),
CreateSetDto(),
CreateSetDto(),
CreateSetDto(),
});
// ACT
var result = _addTypeToSetDto.Execute(_database, new MongoStorageOptions(), _mongoMigrationBagMock.Object);

// ASSERT
Assert.True(result, "Expected migration to be successful, reported 'false'");
var migrated = collection.Find(new BsonDocument("_t", "SetDto")).ToList();
foreach (var doc in migrated)
{
Assert.True(doc.Contains("SetType"));
}

var index = collection.Indexes.List().ToList().FirstOrDefault(b => b["name"].AsString == "SetType");
Assert.NotNull(index);
}

public BsonDocument CreateSetDto()
{
var value = _random.Next(123, 234);
return new BsonDocument
{
["Key"] = $"schedule<{value}>",
["Score"] = (double) _random.Next(12124124, 193435467),
["Value"] = value.ToString(),
["ExpireAt"] = DateTime.UtcNow.AddDays(2),
["_t"] = "SetDto",
["_id"] = ObjectId.GenerateNewId()
};
}
}
}
Loading

0 comments on commit 7c3ae99

Please sign in to comment.