File tree 3 files changed +24
-5
lines changed
src/Symfony/Component/Lock
3 files changed +24
-5
lines changed Original file line number Diff line number Diff line change @@ -105,22 +105,25 @@ public function acquire($blocking = false)
105
105
/**
106
106
* {@inheritdoc}
107
107
*/
108
- public function refresh ()
108
+ public function refresh ($ ttl = null )
109
109
{
110
- if (!$ this ->ttl ) {
110
+ if (null === $ ttl ) {
111
+ $ ttl = $ this ->ttl ;
112
+ }
113
+ if (!$ ttl ) {
111
114
throw new InvalidArgumentException ('You have to define an expiration duration. ' );
112
115
}
113
116
114
117
try {
115
118
$ this ->key ->resetLifetime ();
116
- $ this ->store ->putOffExpiration ($ this ->key , $ this -> ttl );
119
+ $ this ->store ->putOffExpiration ($ this ->key , $ ttl );
117
120
$ this ->dirty = true ;
118
121
119
122
if ($ this ->key ->isExpired ()) {
120
123
throw new LockExpiredException (sprintf ('Failed to put off the expiration of the "%s" lock within the specified time. ' , $ this ->key ));
121
124
}
122
125
123
- $ this ->logger ->info ('Expiration defined for "{resource}" lock for "{ttl}" seconds. ' , array ('resource ' => $ this ->key , 'ttl ' => $ this -> ttl ));
126
+ $ this ->logger ->info ('Expiration defined for "{resource}" lock for "{ttl}" seconds. ' , array ('resource ' => $ this ->key , 'ttl ' => $ ttl ));
124
127
} catch (LockConflictedException $ e ) {
125
128
$ this ->dirty = false ;
126
129
$ this ->logger ->notice ('Failed to define an expiration for the "{resource}" lock, someone else acquired the lock. ' , array ('resource ' => $ this ->key ));
Original file line number Diff line number Diff line change @@ -38,10 +38,12 @@ public function acquire($blocking = false);
38
38
/**
39
39
* Increase the duration of an acquired lock.
40
40
*
41
+ * @param float|null $ttl Maximum expected lock duration in seconds.
42
+ *
41
43
* @throws LockConflictedException If the lock is acquired by someone else
42
44
* @throws LockAcquiringException If the lock can not be refreshed
43
45
*/
44
- public function refresh ();
46
+ public function refresh ($ ttl = null );
45
47
46
48
/**
47
49
* Returns whether or not the lock is acquired.
Original file line number Diff line number Diff line change @@ -97,6 +97,20 @@ public function testRefresh()
97
97
$ lock ->refresh ();
98
98
}
99
99
100
+ public function testRefreshCustom ()
101
+ {
102
+ $ key = new Key (uniqid (__METHOD__ , true ));
103
+ $ store = $ this ->getMockBuilder (StoreInterface::class)->getMock ();
104
+ $ lock = new Lock ($ key , $ store , 10 );
105
+
106
+ $ store
107
+ ->expects ($ this ->once ())
108
+ ->method ('putOffExpiration ' )
109
+ ->with ($ key , 20 );
110
+
111
+ $ lock ->refresh (20 );
112
+ }
113
+
100
114
public function testIsAquired ()
101
115
{
102
116
$ key = new Key (uniqid (__METHOD__ , true ));
You can’t perform that action at this time.
0 commit comments