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 @@ -118,7 +118,9 @@ method, the resource will stay locked until the timeout::
118
118
// create an expiring lock that lasts 30 seconds
119
119
$lock = $factory->createLock('charts-generation', 30);
120
120
121
- $lock->acquire();
121
+ if (!$lock->acquire()) {
122
+ return;
123
+ }
122
124
try {
123
125
// perform a job during less than 30 seconds
124
126
} finally {
@@ -137,7 +139,9 @@ to reset the TTL to its original value::
137
139
// ...
138
140
$lock = $factory->createLock('charts-generation', 30);
139
141
140
- $lock->acquire();
142
+ if (!$lock->acquire()) {
143
+ return;
144
+ }
141
145
try {
142
146
while (!$finished) {
143
147
// perform a small part of the job.
@@ -455,7 +459,9 @@ Using the above methods, a more robust code would be::
455
459
// ...
456
460
$lock = $factory->createLock('invoice-publication', 30);
457
461
458
- $lock->acquire();
462
+ if (!$lock->acquire()) {
463
+ return;
464
+ }
459
465
while (!$finished) {
460
466
if ($lock->getRemainingLifetime() <= 5) {
461
467
if ($lock->isExpired()) {
You can’t perform that action at this time.
0 commit comments