-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1706 from bcgov/redis-lock
Add initial redis lock implementation
- Loading branch information
Showing
13 changed files
with
548 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,47 @@ | ||
namespace TrafficCourts.Staff.Service.Models; | ||
|
||
public class Lock | ||
{ | ||
/// <summary> | ||
/// The function that returns the current UTC date and time. Overriden for tests. | ||
/// </summary> | ||
private readonly Func<DateTimeOffset> _utcNow; | ||
|
||
public Lock() : this(() => DateTimeOffset.UtcNow) | ||
{ | ||
} | ||
|
||
internal Lock(Func<DateTimeOffset> utcNow) | ||
{ | ||
_utcNow = utcNow ?? throw new ArgumentNullException(nameof(utcNow)); | ||
CreatedAtUtc = _utcNow(); | ||
} | ||
|
||
/// <summary> | ||
/// Lock ID | ||
/// </summary> | ||
public string? LockId { get; set; } | ||
|
||
/// <summary> | ||
/// The ticket number associated with the dispute. | ||
/// </summary> | ||
public string TicketNumber { get; set; } = string.Empty; | ||
|
||
/// <summary> | ||
/// Username of the person who acquired the lock. | ||
/// </summary> | ||
public string Username { get; set; } = string.Empty; | ||
|
||
/// <summary> | ||
/// The time in UTC when the acquired lock expires. | ||
/// </summary> | ||
public DateTimeOffset ExpiryTimeUtc { get; set; } | ||
|
||
/// <summary> | ||
/// The time in UTC when the lock was created. | ||
/// </summary> | ||
public DateTimeOffset CreatedAtUtc { get; } | ||
} | ||
using System; | ||
|
||
namespace TrafficCourts.Staff.Service.Models; | ||
|
||
public class Lock | ||
{ | ||
private readonly TimeProvider _timeProvider; | ||
|
||
public Lock() : this(TimeProvider.System) | ||
{ | ||
} | ||
|
||
internal Lock(TimeProvider timeProvider) | ||
{ | ||
ArgumentNullException.ThrowIfNull(timeProvider); | ||
CreatedAtUtc = timeProvider.GetUtcNow(); | ||
_timeProvider = timeProvider; | ||
} | ||
|
||
/// <summary> | ||
/// Lock ID | ||
/// </summary> | ||
public string LockId { get; set; } = string.Empty; | ||
|
||
/// <summary> | ||
/// The ticket number associated with the dispute. | ||
/// </summary> | ||
public string TicketNumber { get; set; } = string.Empty; | ||
|
||
/// <summary> | ||
/// Username of the person who acquired the lock. | ||
/// </summary> | ||
public string Username { get; set; } = string.Empty; | ||
|
||
/// <summary> | ||
/// The time in UTC when the acquired lock expires. | ||
/// </summary> | ||
public DateTimeOffset ExpiryTimeUtc { get; set; } | ||
|
||
/// <summary> | ||
/// The time in UTC when the lock was created. | ||
/// </summary> | ||
public DateTimeOffset CreatedAtUtc { get; set; } | ||
|
||
[System.Text.Json.Serialization.JsonIgnore] | ||
public bool IsExpired => ExpiryTimeUtc < _timeProvider.GetUtcNow(); | ||
} |
Oops, something went wrong.