File tree 1 file changed +9
-3
lines changed
1 file changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -117,7 +117,9 @@ method, the resource will stay locked until the timeout::
117
117
// create an expiring lock that lasts 30 seconds
118
118
$lock = $factory->createLock('charts-generation', 30);
119
119
120
- $lock->acquire();
120
+ if (!$lock->acquire()) {
121
+ return;
122
+ }
121
123
try {
122
124
// perform a job during less than 30 seconds
123
125
} finally {
@@ -136,7 +138,9 @@ to reset the TTL to its original value::
136
138
// ...
137
139
$lock = $factory->createLock('charts-generation', 30);
138
140
139
- $lock->acquire();
141
+ if (!$lock->acquire()) {
142
+ return;
143
+ }
140
144
try {
141
145
while (!$finished) {
142
146
// perform a small part of the job.
@@ -366,7 +370,9 @@ Using the above methods, a more robust code would be::
366
370
// ...
367
371
$lock = $factory->createLock('invoice-publication', 30);
368
372
369
- $lock->acquire();
373
+ if (!$lock->acquire()) {
374
+ return;
375
+ }
370
376
while (!$finished) {
371
377
if ($lock->getRemainingLifetime() <= 5) {
372
378
if ($lock->isExpired()) {
You can’t perform that action at this time.
0 commit comments