MemoryStorage Missing ParametersSnapshot Property in ApplyStateContext
Description
The Hangfire.MemoryStorage plugin does not correctly implement the ParametersSnapshot property in the ApplyStateContext. This causes exceptions when using state filters that depend on this property.
Details
When comparing with the official SQL Storage implementation, the following differences are observed:
Steps to Reproduce
Create a state filter that accesses ParametersSnapshot:
public class OrchestratorStateFilter : IApplyStateFilter
{
public void OnStateApplied(
ApplyStateContext context,
IWriteOnlyTransaction tx)
{
var backgroundJob = context.BackgroundJob;
if (!FilterHelper.IsOrchestratorNode(backgroundJob.Job))
return;
#region Metadata base
if (backgroundJob.ParametersSnapshot is null)
{
throw new Exception("ParametersSnapshot empty");
}
// ... rest of code
#endregion
}
}
Result: Exception is thrown when using Memory Storage, while SQL Storage works correctly.
Expected Behavior
The ParametersSnapshot property should be implemented in ApplyStateContext consistently with the official SQL Storage implementation.
Impact
- Custom state filters that depend on
ParametersSnapshot fail
- Incompatibility with Hangfire's standard interface
- Code that works with SQL Storage does not work with Memory Storage
Related References
IApplyStateFilter interface: Official Hangfire documentation
- SQL Server Storage implementation: Reference implementation
Environment
- Hangfire.MemoryStorage
- Hangfire
Official sql storage.
https://github.com/HangfireIO/Hangfire/blob/333bd8eb228402abcee3f261cf32412e844f32c0/src/Hangfire.SqlServer/SqlServerConnection.cs#L286
Vs
memory storage
|
LoadException = loadException |
alternative
Hangfire.InMemory
MemoryStorage Missing ParametersSnapshot Property in ApplyStateContext
Description
The
Hangfire.MemoryStorageplugin does not correctly implement theParametersSnapshotproperty in theApplyStateContext. This causes exceptions when using state filters that depend on this property.Details
When comparing with the official SQL Storage implementation, the following differences are observed:
SQL Storage (Official): Correctly implements
ParametersSnapshotin theApplyStatefrom GetJobData methodMemory Storage (Current): Does not assign
ParametersSnapshotinApplyStateContextSteps to Reproduce
Create a state filter that accesses
ParametersSnapshot:Result: Exception is thrown when using Memory Storage, while SQL Storage works correctly.
Expected Behavior
The
ParametersSnapshotproperty should be implemented inApplyStateContextconsistently with the official SQL Storage implementation.Impact
ParametersSnapshotfailRelated References
IApplyStateFilterinterface: Official Hangfire documentationEnvironment
Official sql storage.
https://github.com/HangfireIO/Hangfire/blob/333bd8eb228402abcee3f261cf32412e844f32c0/src/Hangfire.SqlServer/SqlServerConnection.cs#L286
Vs
memory storage
Hangfire.MemoryStorage/src/Hangfire.MemoryStorage/MemoryStorageConnection.cs
Line 216 in d41fb18
alternative
Hangfire.InMemory