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 @@ -117,7 +117,9 @@ method, the resource will stay locked until the timeout::
117117 // create an expiring lock that lasts 30 seconds
118118 $lock = $factory->createLock('charts-generation', 30);
119119
120- $lock->acquire();
120+ if (!$lock->acquire()) {
121+ return;
122+ }
121123 try {
122124 // perform a job during less than 30 seconds
123125 } finally {
@@ -136,7 +138,9 @@ to reset the TTL to its original value::
136138 // ...
137139 $lock = $factory->createLock('charts-generation', 30);
138140
139- $lock->acquire();
141+ if (!$lock->acquire()) {
142+ return;
143+ }
140144 try {
141145 while (!$finished) {
142146 // perform a small part of the job.
@@ -366,7 +370,9 @@ Using the above methods, a more robust code would be::
366370 // ...
367371 $lock = $factory->createLock('invoice-publication', 30);
368372
369- $lock->acquire();
373+ if (!$lock->acquire()) {
374+ return;
375+ }
370376 while (!$finished) {
371377 if ($lock->getRemainingLifetime() <= 5) {
372378 if ($lock->isExpired()) {
You can’t perform that action at this time.
0 commit comments