File tree Expand file tree Collapse file tree 1 file changed +9
-3
lines changed
Expand file tree Collapse file tree 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::
118118 // create an expiring lock that lasts 30 seconds
119119 $lock = $factory->createLock('charts-generation', 30);
120120
121- $lock->acquire();
121+ if (!$lock->acquire()) {
122+ return;
123+ }
122124 try {
123125 // perform a job during less than 30 seconds
124126 } finally {
@@ -137,7 +139,9 @@ to reset the TTL to its original value::
137139 // ...
138140 $lock = $factory->createLock('charts-generation', 30);
139141
140- $lock->acquire();
142+ if (!$lock->acquire()) {
143+ return;
144+ }
141145 try {
142146 while (!$finished) {
143147 // perform a small part of the job.
@@ -455,7 +459,9 @@ Using the above methods, a more robust code would be::
455459 // ...
456460 $lock = $factory->createLock('invoice-publication', 30);
457461
458- $lock->acquire();
462+ if (!$lock->acquire()) {
463+ return;
464+ }
459465 while (!$finished) {
460466 if ($lock->getRemainingLifetime() <= 5) {
461467 if ($lock->isExpired()) {
You can’t perform that action at this time.
0 commit comments