namespace Nop.Core.Caching; public partial interface ILocker { /// /// Performs some asynchronous task with exclusive lock /// /// The key we are locking on /// The time after which the lock will automatically be expired /// Asynchronous task to be performed with locking /// A task that resolves true if lock was acquired and action was performed; otherwise false Task PerformActionWithLockAsync(string resource, TimeSpan expirationTime, Func action); /// /// Starts a background task with "heartbeat": a status flag that will be periodically updated to signal to /// others that the task is running and stop them from starting the same task. /// /// The key of the background task /// The time after which the heartbeat key will automatically be expired. Should be longer than /// The interval at which to update the heartbeat, if required by the implementation /// Asynchronous background task to be performed /// A CancellationTokenSource for manually canceling the task /// A task that resolves true if lock was acquired and action was performed; otherwise false Task RunWithHeartbeatAsync(string key, TimeSpan expirationTime, TimeSpan heartbeatInterval, Func action, CancellationTokenSource cancellationTokenSource = default); /// /// Tries to cancel a background task by flagging it for cancellation on the next heartbeat. /// /// The task's key /// The time after which the task will be considered stopped due to system shutdown or other causes, /// even if not explicitly canceled. /// A task that represents requesting cancellation of the task. Note that the completion of this task does not /// necessarily imply that the task has been canceled, only that cancellation has been requested. Task CancelTaskAsync(string key, TimeSpan expirationTime); /// /// Check if a background task is running. /// /// The task's key /// A task that resolves to true if the background task is running; otherwise false Task IsTaskRunningAsync(string key); }