up
This commit is contained in:
		
							
								
								
									
										72
									
								
								src/StellaOps.Scanner.Queue/Redis/RedisScanQueueLease.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										72
									
								
								src/StellaOps.Scanner.Queue/Redis/RedisScanQueueLease.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,72 @@
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Threading;
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
 | 
			
		||||
namespace StellaOps.Scanner.Queue.Redis;
 | 
			
		||||
 | 
			
		||||
internal sealed class RedisScanQueueLease : IScanQueueLease
 | 
			
		||||
{
 | 
			
		||||
    private readonly RedisScanQueue _queue;
 | 
			
		||||
    private int _completed;
 | 
			
		||||
 | 
			
		||||
    internal RedisScanQueueLease(
 | 
			
		||||
        RedisScanQueue queue,
 | 
			
		||||
        string messageId,
 | 
			
		||||
        string jobId,
 | 
			
		||||
        byte[] payload,
 | 
			
		||||
        int attempt,
 | 
			
		||||
        DateTimeOffset enqueuedAt,
 | 
			
		||||
        DateTimeOffset leaseExpiresAt,
 | 
			
		||||
        string consumer,
 | 
			
		||||
        string? idempotencyKey,
 | 
			
		||||
        IReadOnlyDictionary<string, string> attributes)
 | 
			
		||||
    {
 | 
			
		||||
        _queue = queue;
 | 
			
		||||
        MessageId = messageId;
 | 
			
		||||
        JobId = jobId;
 | 
			
		||||
        Payload = payload;
 | 
			
		||||
        Attempt = attempt;
 | 
			
		||||
        EnqueuedAt = enqueuedAt;
 | 
			
		||||
        LeaseExpiresAt = leaseExpiresAt;
 | 
			
		||||
        Consumer = consumer;
 | 
			
		||||
        IdempotencyKey = idempotencyKey;
 | 
			
		||||
        Attributes = attributes;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public string MessageId { get; }
 | 
			
		||||
 | 
			
		||||
    public string JobId { get; }
 | 
			
		||||
 | 
			
		||||
    public ReadOnlyMemory<byte> Payload { get; }
 | 
			
		||||
 | 
			
		||||
    public int Attempt { get; }
 | 
			
		||||
 | 
			
		||||
    public DateTimeOffset EnqueuedAt { get; }
 | 
			
		||||
 | 
			
		||||
    public DateTimeOffset LeaseExpiresAt { get; private set; }
 | 
			
		||||
 | 
			
		||||
    public string Consumer { get; }
 | 
			
		||||
 | 
			
		||||
    public string? IdempotencyKey { get; }
 | 
			
		||||
 | 
			
		||||
    public IReadOnlyDictionary<string, string> Attributes { get; }
 | 
			
		||||
 | 
			
		||||
    public Task AcknowledgeAsync(CancellationToken cancellationToken = default)
 | 
			
		||||
        => _queue.AcknowledgeAsync(this, cancellationToken);
 | 
			
		||||
 | 
			
		||||
    public Task RenewAsync(TimeSpan leaseDuration, CancellationToken cancellationToken = default)
 | 
			
		||||
        => _queue.RenewLeaseAsync(this, leaseDuration, cancellationToken);
 | 
			
		||||
 | 
			
		||||
    public Task ReleaseAsync(QueueReleaseDisposition disposition, CancellationToken cancellationToken = default)
 | 
			
		||||
        => _queue.ReleaseAsync(this, disposition, cancellationToken);
 | 
			
		||||
 | 
			
		||||
    public Task DeadLetterAsync(string reason, CancellationToken cancellationToken = default)
 | 
			
		||||
        => _queue.DeadLetterAsync(this, reason, cancellationToken);
 | 
			
		||||
 | 
			
		||||
    internal bool TryBeginCompletion()
 | 
			
		||||
        => Interlocked.CompareExchange(ref _completed, 1, 0) == 0;
 | 
			
		||||
 | 
			
		||||
    internal void RefreshLease(DateTimeOffset expiresAt)
 | 
			
		||||
        => LeaseExpiresAt = expiresAt;
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user