Skip to content

Commit 08a8bbd

Browse files
patrickerpatri
andauthored
Expose Queue Depth (#49)
* Expose Queue Depth * Renaming methods based on feedback Fixes #48 Co-authored-by: patri <patri@DESKTOP-KT98APM>
1 parent 8244da4 commit 08a8bbd

File tree

4 files changed

+17
-0
lines changed

4 files changed

+17
-0
lines changed

IBackend.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ public interface IBackend
1313

1414
Task<IEnumerable<string>> DequeueBatch(string queueKey, int batchSize=100);
1515

16+
Task<long> QueueCount(string key);
17+
1618
Task<IBackendLock> LockBlocking(string lockKey);
1719

1820
Task<IBackendLock> LockNonBlocking(string lockKey);

RedisBackend.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ public async Task<IEnumerable<string>> DequeueBatch(string queueKey, int batchSi
3838
return jsonStrings.Select(v => (string) v);
3939
}
4040

41+
public async Task<long> QueueCount(string queueKey)
42+
{
43+
return await RedisQueue.Count(queueKey);
44+
}
45+
4146
public async Task<IBackendLock> LockBlocking(string lockKey)
4247
{
4348
return await Redis.LockBlockingAsync(lockKey);

RedisQueue.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ public RedisQueue(ConnectionMultiplexer redis)
2626
Redis = redis;
2727
}
2828

29+
public async Task<long> Count(RedisKey queueName)
30+
{
31+
return await Redis.GetDatabase().ListLengthAsync(queueName);
32+
}
33+
2934
public async Task Push(RedisKey queueName, RedisValue value)
3035
{
3136
await Redis.GetDatabase().ListLeftPushAsync(queueName, value);

TaskQueue.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ internal async Task Enqueue(TaskInfo taskInfo)
4343

4444
await Backend.Enqueue(Config.QueueName, jsonString);
4545
}
46+
47+
public async Task<long> Count()
48+
{
49+
return await Backend.QueueCount(Config.QueueName);
50+
}
4651

4752
public async Task<bool> ExecuteNext()
4853
{

0 commit comments

Comments
 (0)