@@ -11,38 +11,24 @@ namespace ServiceStack.Redis.Support.Queue.Implementation
1111 ///
1212 ///
1313 /// </summary>
14- public partial class RedisSequentialWorkQueue < T > : RedisWorkQueue < T > , ISequentialWorkQueue < T > where T : class
14+ public partial class RedisSequentialWorkQueue < T >
1515 {
16- public class DequeueLockFactory : DistributedLockFactory
17- {
18- protected readonly RedisSequentialWorkQueue < T > workQueue ;
19- protected readonly string workItemId ;
20- protected readonly PooledRedisClientManager clientManager ;
21- public DequeueLockFactory ( IRedisClient client , PooledRedisClientManager clientManager , RedisSequentialWorkQueue < T > workQueue , string workItemId )
22- : base ( client )
23- {
24- this . clientManager = clientManager ;
25- this . workQueue = workQueue ;
26- this . workItemId = workItemId ;
27- }
28- public override IDistributedLock CreateLock ( )
29- {
30- return new DequeueLock ( client , clientManager , workQueue , workItemId ) ;
31- }
32- }
3316
3417 public class DequeueLock : DistributedLock
3518 {
3619 private bool ownsClient ;
3720 protected readonly RedisSequentialWorkQueue < T > workQueue ;
3821 protected readonly string workItemId ;
3922 protected readonly PooledRedisClientManager clientManager ;
40- public DequeueLock ( IRedisClient client , PooledRedisClientManager clientManager , RedisSequentialWorkQueue < T > workQueue , string workItemId ) : base ( client )
23+ protected readonly int numberOfDequeuedItems ;
24+ protected int numberOfProcessedItems ;
25+ public DequeueLock ( IRedisClient client , PooledRedisClientManager clientManager , RedisSequentialWorkQueue < T > workQueue , string workItemId , int numberOfDequeuedItems ) : base ( client )
4126 {
4227 this . workQueue = workQueue ;
4328 this . workItemId = workItemId ;
4429 this . clientManager = clientManager ;
4530 ownsClient = false ;
31+ this . numberOfDequeuedItems = numberOfDequeuedItems ;
4632 }
4733
4834 public override long Lock ( string key , int acquisitionTimeout , int lockTimeout )
@@ -53,6 +39,13 @@ public override long Lock(string key, int acquisitionTimeout, int lockTimeout)
5339 return rc ;
5440 }
5541
42+ public void DoneProcessedWorkItem ( )
43+ {
44+ numberOfProcessedItems ++ ;
45+ if ( numberOfProcessedItems == numberOfDequeuedItems )
46+ Unlock ( ) ;
47+ }
48+
5649 public override bool Unlock ( )
5750 {
5851 workQueue . Unlock ( workItemId ) ;
@@ -80,16 +73,15 @@ protected override RedisClient AcquireClient()
8073 }
8174 public class DeferredDequeueLock : DequeueLock
8275 {
83- private readonly int numberofPeekedItems ;
84- public DeferredDequeueLock ( IRedisClient client , PooledRedisClientManager clientManager , RedisSequentialWorkQueue < T > workQueue , string workItemId , int numberofPeekedItems )
85- : base ( client , clientManager , workQueue , workItemId )
76+ public DeferredDequeueLock ( IRedisClient client , PooledRedisClientManager clientManager , RedisSequentialWorkQueue < T > workQueue , string workItemId , int numberOfDequeuedItems )
77+ : base ( client , clientManager , workQueue , workItemId , numberOfDequeuedItems )
8678 {
87- this . numberofPeekedItems = numberofPeekedItems ;
8879 }
80+
8981 public override bool Unlock ( )
9082 {
9183 //remove items from queue
92- workQueue . Pop ( workItemId , numberofPeekedItems ) ;
84+ workQueue . Pop ( workItemId , numberOfDequeuedItems ) ;
9385
9486 // unlock work queue id
9587 workQueue . Unlock ( workItemId ) ;
0 commit comments