Skip to content

Commit

Permalink
#97: Update Hangfire.SQLServer to reflect changes in Hangfire 1.8.15
Browse files Browse the repository at this point in the history
  • Loading branch information
r-win committed Dec 3, 2024
1 parent 5038a69 commit 08bfb61
Show file tree
Hide file tree
Showing 11 changed files with 83 additions and 49 deletions.
1 change: 1 addition & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ environment:
branches:
only:
- main
- feature/issue-97

pull_requests:
do_not_increment_build_number: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Hangfire" Version="1.8.2" />
<PackageReference Include="Hangfire" Version="1.8.15" />
<PackageReference Include="Hangfire.Heartbeat" Version="0.5.1" />
<PackageReference Include="Hangfire.Mongo" Version="1.9.6" />
<PackageReference Include="Hangfire.MySqlStorage" Version="2.0.3" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@
<Reference Include="DnsClient, Version=1.6.1.0, Culture=neutral, PublicKeyToken=4574bb5573c51424, processorArchitecture=MSIL">
<HintPath>..\..\packages\DnsClient.1.6.1\lib\net471\DnsClient.dll</HintPath>
</Reference>
<Reference Include="Hangfire.Core, Version=1.8.2.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Hangfire.Core.1.8.2\lib\net46\Hangfire.Core.dll</HintPath>
<Reference Include="Hangfire.Core, Version=1.8.15.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Hangfire.Core.1.8.15\lib\net46\Hangfire.Core.dll</HintPath>
</Reference>
<Reference Include="Hangfire.Mongo, Version=0.7.28.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Hangfire.Mongo.1.9.6\lib\netstandard2.0\Hangfire.Mongo.dll</HintPath>
Expand All @@ -77,8 +77,8 @@
<Reference Include="Hangfire.Redis.StackExchange, Version=1.8.7.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Hangfire.Redis.StackExchange.1.8.7\lib\net462\Hangfire.Redis.StackExchange.dll</HintPath>
</Reference>
<Reference Include="Hangfire.SqlServer, Version=1.8.2.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Hangfire.SqlServer.1.8.2\lib\net451\Hangfire.SqlServer.dll</HintPath>
<Reference Include="Hangfire.SqlServer, Version=1.8.15.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Hangfire.SqlServer.1.8.15\lib\net451\Hangfire.SqlServer.dll</HintPath>
</Reference>
<Reference Include="Hangfire.Storage.SQLite, Version=0.3.4.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Hangfire.Storage.SQLite.0.3.4\lib\net48\Hangfire.Storage.SQLite.dll</HintPath>
Expand Down
4 changes: 2 additions & 2 deletions samples/Hangfire.MvcApplication/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
<package id="bootstrap" version="4.3.1" targetFramework="net472" />
<package id="Dapper" version="2.1.28" targetFramework="net48" />
<package id="DnsClient" version="1.6.1" targetFramework="net472" />
<package id="Hangfire.Core" version="1.8.2" targetFramework="net472" />
<package id="Hangfire.Core" version="1.8.15" targetFramework="net48" />
<package id="Hangfire.Mongo" version="1.9.6" targetFramework="net472" />
<package id="Hangfire.MySqlStorage" version="2.0.3" targetFramework="net472" />
<package id="Hangfire.Pro.Redis" version="3.0.4" targetFramework="net48" />
<package id="Hangfire.Redis.StackExchange" version="1.8.7" targetFramework="net472" />
<package id="Hangfire.SqlServer" version="1.8.2" targetFramework="net472" />
<package id="Hangfire.SqlServer" version="1.8.15" targetFramework="net48" />
<package id="Hangfire.Storage.SQLite" version="0.3.4" targetFramework="net48" />
<package id="jQuery" version="3.3.1" targetFramework="net472" />
<package id="Microsoft.AspNet.Mvc" version="5.2.9" targetFramework="net472" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Hangfire.AspNetCore" Version="1.8.2" />
<PackageReference Include="Hangfire.SqlServer" Version="1.8.2" />
<PackageReference Include="Hangfire.AspNetCore" Version="1.8.15" />
<PackageReference Include="Hangfire.SqlServer" Version="1.8.15" />
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.1.1" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Hangfire.AspNetCore" Version="1.8.2" />
<PackageReference Include="Hangfire.SqlServer" Version="1.8.2" />
<PackageReference Include="Hangfire.AspNetCore" Version="1.8.15" />
<PackageReference Include="Hangfire.SqlServer" Version="1.8.15" />
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.1.3" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Hangfire.AspNetCore" Version="1.8.2" />
<PackageReference Include="Hangfire.SqlServer" Version="1.8.2" />
<PackageReference Include="Hangfire.AspNetCore" Version="1.8.15" />
<PackageReference Include="Hangfire.SqlServer" Version="1.8.15" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.2.0" />
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.1.1" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,5 @@
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:54863",
"sslPort": 44325
}
},
"profiles": {
"IIS Express": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"MultipleDashboards": {
"commandName": "Project",
"launchBrowser": true,
Expand All @@ -24,5 +9,13 @@
},
"applicationUrl": "https://localhost:5001;http://localhost:5000"
}
},
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:54863",
"sslPort": 44325
}
}
}
52 changes: 52 additions & 0 deletions src/FaceIT.Hangfire.Tags.SqlServer/DbCommandExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System;
using System.Data.Common;
using System.Data;
using Hangfire.Annotations;

namespace Hangfire.Tags.SqlServer
{
internal static class DbCommandExtensions
{
public static DbCommand Create(
[NotNull] this DbConnection connection,
[NotNull] string text,
CommandType type = CommandType.Text,
int? timeout = null)
{
if (connection == null) throw new ArgumentNullException(nameof(connection));
if (text == null) throw new ArgumentNullException(nameof(text));

var command = connection.CreateCommand();
command.CommandType = type;
command.CommandText = text;

if (timeout.HasValue)
{
command.CommandTimeout = timeout.Value;
}

return command;
}

public static DbCommand AddParameter(
[NotNull] this DbCommand command,
[NotNull] string parameterName,
[CanBeNull] object value,
DbType dbType,
[CanBeNull] int? size = null)
{
if (command == null) throw new ArgumentNullException(nameof(command));
if (parameterName == null) throw new ArgumentNullException(nameof(parameterName));

var parameter = command.CreateParameter();
parameter.ParameterName = parameterName;
parameter.DbType = dbType;
parameter.Value = value ?? DBNull.Value;

if (size.HasValue) parameter.Size = size.Value;

command.Parameters.Add(parameter);
return command;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<Authors>Erwin Bovendeur</Authors>
<Company>faceit</Company>
<Version>1.9.2</Version>
<Version>1.9.15-beta.1</Version>
<Description>Support for SQL Server for Hangfire.Tags. This seperate library is required in order to search for tags, and proper cleanup.</Description>
<Copyright />
<PackageProjectUrl>https://github.com/face-it/Hangfire.Tags</PackageProjectUrl>
Expand All @@ -32,7 +32,7 @@

<ItemGroup>
<PackageReference Include="Dapper" Version="2.0.4" />
<PackageReference Include="Hangfire.SqlServer" Version="1.8.2" />
<PackageReference Include="Hangfire.SqlServer" Version="1.8.15" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
</ItemGroup>

Expand Down
26 changes: 7 additions & 19 deletions src/FaceIT.Hangfire.Tags.SqlServer/SqlTagsTransaction.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using System;
using System.Data;
using System.Linq;
using System.Data.Common;
using System.Reflection;
using Dapper;
using Hangfire.SqlServer;
using Hangfire.Storage;
using Hangfire.Tags.Storage;
Expand All @@ -26,9 +27,6 @@ internal class SqlTagsTransaction : ITagsTransaction

private static Type _type;
private static MethodInfo _acquireSetLock;
private static Type _sqlCommandBatchParameter;
private static ConstructorInfo _sqlCommandBatchParameterCtor;
private static PropertyInfo _sqlCommandBatchParameterValue;

private static MethodInfo _addCommand;

Expand Down Expand Up @@ -67,14 +65,6 @@ public SqlTagsTransaction(SqlServerStorageOptions options, IWriteOnlyTransaction

if (_addCommand == null)
throw new ArgumentException("The functions QueueCommand and AddCommand cannot be found.");

if (_sqlCommandBatchParameter == null)
{
_sqlCommandBatchParameter = Type.GetType("Hangfire.SqlServer.SqlCommandBatchParameter, Hangfire.SqlServer");
_sqlCommandBatchParameterCtor =
_sqlCommandBatchParameter.GetConstructor(new Type[] {typeof(string), typeof(DbType), typeof(int?)});
_sqlCommandBatchParameterValue = _sqlCommandBatchParameter.GetProperty("Value");
}
}

private void AcquireSetLock(string key)
Expand All @@ -85,17 +75,15 @@ private void AcquireSetLock(string key)

private void AddCommand(string commandText, string key, params SqlCommandBatchParameter[] parameters)
{
var batchParams = Array.CreateInstance(_sqlCommandBatchParameter, parameters.Length);
for (var i = 0; i < parameters.Length; i++)
DbCommand Command(DbConnection connection)
{
var p = parameters[i];
var param = _sqlCommandBatchParameterCtor.Invoke(new object[] { p.ParameterName, p.DbType, null });
_sqlCommandBatchParameterValue.SetValue(param, p.Value);
batchParams.SetValue(param, i);
var cmd = connection.Create(commandText);
foreach (var sqlParameter in parameters) cmd.AddParameter(sqlParameter.ParameterName, sqlParameter.Value, sqlParameter.DbType);
return cmd;
}

var setCommands = _transaction.GetType().GetTypeInfo().GetField("_setCommands", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(_transaction);
_addCommand.Invoke(_transaction, new object[] { setCommands, key, commandText, batchParams });
_addCommand.Invoke(_transaction, new[] {setCommands, key, (Func<DbConnection, DbCommand>) Command});
}

public void ExpireSetValue(string key, string value, TimeSpan expireIn)
Expand Down

0 comments on commit 08bfb61

Please sign in to comment.