public void SaveCheckpoint(long checkpoint) { if (!_started) { _timer.Start(); _started = true; } _bufferCheckpointManager.SaveCheckpoint(checkpoint); }
public EfDistributedLock(Func <AggregateDbContext> contextFactory, EfDistributedLockRecord record, TimeSpan expiration, Action expirationAction = null) { Guard.ArgumentNotNull(contextFactory, nameof(contextFactory)); Guard.ArgumentNotNull(record, nameof(record)); Guard.ArgumentNotNull(expiration, nameof(expiration)); _action = expirationAction; _contextFactory = contextFactory; Expiry = expiration; ExpirationTime = record.LockDateTime; IsAcquired = record.IsAcquired(); LockName = record.Name; LockId = record.LockId; var extendTime = (expiration.TotalMilliseconds * 0.9).Do(Convert.ToInt32); _timer = new PeriodicAction(ct => ExtendLockAsync(ct), extendTime, null, true); _timer.Start(); }
public async Task <IDistributedLock> CreateLockAsync(string name, TimeSpan expiry, TimeSpan wait, TimeSpan retry, CancellationToken cancellationToken, Action expirationAction = null) { IDistributedLock result = null; PeriodicAction timer = null; timer = new PeriodicAction(async ct => { var dlock = await TryAquireLock(name, expiry, expirationAction); if (dlock != null) { result = dlock; timer?.Stop(); } }, Convert.ToInt32(retry.TotalMilliseconds), wait); cancellationToken.Register(() => timer.Stop()); using (var scope = TraceContext.Begin()) { _logger.TraceVerboseEvent($"Starting trying to acquire lock {name} for {wait} each {retry}"); await timer.Start(); return(result ?? new EfDistributedLock(name)); } }