Completed
Push — 2.0 ( dbbe01...d43752 )
by Marco
11:55
created

Manager::updateTrackerSetQueued()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
1
<?php namespace Comodojo\Extender\Task;
2
3
use \Comodojo\Foundation\Base\Configuration;
4
use \Comodojo\Foundation\Events\Manager as EventsManager;
5
use \Comodojo\Foundation\Logging\LoggerTrait;
6
use \Comodojo\Foundation\Events\EventsTrait;
7
use \Comodojo\Daemon\Utils\ProcessTools;
8
use \Comodojo\Foundation\Base\ConfigurationTrait;
9
use \Comodojo\Extender\Traits\TasksTableTrait;
10
use \Comodojo\Extender\Utils\Validator as ExtenderCommonValidations;
11
use \Comodojo\Extender\Components\Ipc;
12
use \Comodojo\Extender\Task\Table as TasksTable;
13
use \Comodojo\Extender\Components\Database;
14
use \Psr\Log\LoggerInterface;
15
use \Exception;
16
17
/**
18
* @package     Comodojo Extender
19
* @author      Marco Giovinazzi <[email protected]>
20
* @license     MIT
21
*
22
* LICENSE:
23
*
24
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
29
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
30
* THE SOFTWARE.
31
 */
32
33
class Manager {
34
35
    use ConfigurationTrait;
36
    use LoggerTrait;
37
    use EventsTrait;
38
    use TasksTableTrait;
39
40
    /**
41
     * @var int
42
     */
43
    protected $lagger_timeout;
44
45
    /**
46
     * @var bool
47
     */
48
    protected $multithread;
49
50
    /**
51
     * @var int
52
     */
53
    protected $max_runtime;
54
55
    /**
56
     * @var int
57
     */
58
    protected $max_childs;
59
60
    /**
61
     * @var Ipc
62
     */
63
    protected $ipc;
64
65
    /**
66
     * @var Locker
67
     */
68
    protected $locker;
69
70
    /**
71
     * @var Tracker
72
     */
73
    protected $tracker;
74
75
    /**
76
     * Class constructor
77
     *
78
     * @param string $manager_name
0 ignored issues
show
Bug introduced by
There is no parameter named $manager_name. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
79
     * @param Configuration $configuration
80
     * @param LoggerInterface $logger
81
     * @param TasksTable $tasks
82
     * @param EventsManager $events
83
     * @param EntityManager $em
0 ignored issues
show
Bug introduced by
There is no parameter named $em. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
84
     */
85
    public function __construct(
86
        Locker $locker,
87
        Configuration $configuration,
88
        LoggerInterface $logger,
89
        TasksTable $tasks,
90
        EventsManager $events
91
    ) {
92
93
        $this->setConfiguration($configuration);
94
        $this->setLogger($logger);
95
        $this->setTasksTable($tasks);
96
        $this->setEvents($events);
97
98
        $this->locker = $locker;
99
        $this->tracker = new Tracker($configuration, $logger);
100
        $this->ipc = new Ipc($configuration);
101
102
        // retrieve parameters
103
        $this->lagger_timeout = ExtenderCommonValidations::laggerTimeout($this->configuration->get('child-lagger-timeout'));
104
        $this->multithread = ExtenderCommonValidations::multithread($this->configuration->get('multithread'));
105
        $this->max_runtime = ExtenderCommonValidations::maxChildRuntime($this->configuration->get('child-max-runtime'));
106
        $this->max_childs = ExtenderCommonValidations::forkLimit($this->configuration->get('fork-limit'));
107
108
        // $logger->debug("Tasks Manager online", array(
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
109
        //     'lagger_timeout' => $this->lagger_timeout,
0 ignored issues
show
Unused Code Comprehensibility introduced by
56% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
110
        //     'multithread' => $this->multithread,
0 ignored issues
show
Unused Code Comprehensibility introduced by
56% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
111
        //     'max_runtime' => $this->max_runtime,
0 ignored issues
show
Unused Code Comprehensibility introduced by
56% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
112
        //     'max_childs' => $this->max_childs,
0 ignored issues
show
Unused Code Comprehensibility introduced by
56% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
113
        //     'tasks_count' => count($this->table)
0 ignored issues
show
Unused Code Comprehensibility introduced by
55% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
114
        // ));
115
116
        set_error_handler([$this, 'customErrorHandler']);
117
118
    }
119
120
    public function __destruct() {
121
122
        restore_error_handler();
123
124
    }
125
126
    public function add(Request $request) {
127
128
        $this->tracker->setQueued($request);
129
130
        return $this;
131
132
    }
133
134
    public function addBulk(array $requests) {
135
136
        foreach ($requests as $id => $request) {
137
138
            if ($request instanceof \Comodojo\Extender\Task\Request) {
139
                $this->add($request);
140
            } else {
141
                $this->logger->error("Skipping invalid request with local id $id: class mismatch");
142
            }
143
144
        }
145
146
        return $this;
147
148
    }
149
150
    public function run() {
151
152
        $this->updateTrackerSetQueued();
153
154
        while ( $this->tracker->countQueued() > 0 ) {
155
156
            // Start to cycle queued tasks
157
            $this->cycle();
158
159
        }
160
161
        $this->ipc->free();
162
163
        return $this->tracker->getCompleted();
164
165
    }
166
167
    public function customErrorHandler($errno, $errstr, $errfile, $errline) {
168
169
        $this->getLogger()->error("Unhandled error ($errno): $errstr [in $errfile line $errline]");
170
171
        return true;
172
173
    }
174
175
    protected function cycle() {
176
177
        foreach ($this->tracker->getQueued() as $uid => $request) {
178
179
            if ( $this->multithread === false ) {
180
181
                $this->runSingleThread($uid, $request);
182
183
            } else {
184
185
                try {
186
187
                    $pid = $this->forker($request);
188
189
                } catch (Exception $e) {
190
191
                    $result = self::generateSyntheticResult($uid, $e->getMessage(), $request->getJid(), false);
192
193
                    $this->updateTrackerSetAborted($uid, $result);
194
195
                    if ( $request->isChain() ) $this->evalChain($request, $result);
196
197
                    continue;
198
199
                }
200
201
                $this->updateTrackerSetRunning($uid, $pid);
202
203
                if ( $this->max_childs > 0 && $this->tracker->countRunning() >= $this->max_childs ) {
204
205
                    while( $this->tracker->countRunning() >= $this->max_childs ) {
206
207
                        $this->catcher();
208
209
                    }
210
211
                }
212
213
            }
214
215
        }
216
217
        // spawn the loop if multithread
218
        if ( $this->multithread === true ) $this->catcher_loop();
219
220
    }
221
222
    protected function runSingleThread($uid, Request $request) {
223
224
        $pid = ProcessTools::getPid();
225
226
        $this->updateTrackerSetRunning($uid, $pid);
227
228
        $result = Runner::fastStart(
229
            $request,
230
            $this->getConfiguration(),
231
            $this->getLogger(),
232
            $this->getTasksTable(),
233
            $this->getEvents()
234
        );
235
236
        if ( $request->isChain() ) $this->evalChain($request, $result);
237
238
        $this->updateTrackerSetCompleted($uid, $result);
239
240
        $success = $result->success === false ? "error" : "success";
0 ignored issues
show
Documentation introduced by
The property success does not exist on object<Comodojo\Extender\Task\Result>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
241
        $this->logger->notice("Task ".$request->getName()."(uid: ".$request->getUid().") ends in $success");
242
243
    }
244
245
    private function forker(Request $request) {
246
247
        $uid = $request->getUid();
248
249
        try {
250
251
            $this->ipc->init($uid);
252
253
        } catch (Exception $e) {
254
255
            $this->logger->error("Aborting task ".$request->getName().": ".$e->getMessage());
256
257
            $this->ipc->hang($uid);
258
259
            throw $e;
260
261
        }
262
263
        $pid = pcntl_fork();
264
265
        if ( $pid == -1 ) {
266
267
            // $this->logger->error("Could not fok job, aborting");
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
268
269
            throw new Exception("Unable to fork job, aborting");
270
271
        } elseif ( $pid ) {
272
273
            //PARENT will take actions on processes later
274
275
            $niceness = $request->getNiceness();
276
277
            if ( $niceness !== null ) ProcessTools::setNiceness($niceness, $pid);
278
279
        } else {
280
281
            $this->ipc->close($uid, Ipc::READER);
282
283
            $result = Runner::fastStart(
284
                $request,
285
                $this->getConfiguration(),
286
                $this->getLogger(),
287
                $this->getTasksTable(),
288
                $this->getEvents()
289
            );
290
291
            $this->ipc->write($uid, serialize($result));
292
293
            $this->ipc->close($uid, Ipc::WRITER);
294
295
            exit(!$result->success);
296
297
        }
298
299
        return $pid;
300
301
    }
302
303
    private function catcher_loop() {
304
305
        while ( !empty($this->tracker->getRunning()) ) {
306
307
            $this->catcher();
308
309
        }
310
311
    }
312
313
    /**
314
     * Catch results from completed jobs
315
     *
316
     */
317
    private function catcher() {
318
319
        foreach ( $this->tracker->getRunning() as $uid => $request ) {
320
321
            if ( ProcessTools::isRunning($request->getPid()) === false ) {
322
323
                $this->ipc->close($uid, Ipc::WRITER);
324
325
                try {
326
327
                    $raw_output = $this->ipc->read($uid);
328
329
                    $result = unserialize(rtrim($raw_output));
330
331
                    $this->ipc->close($uid, Ipc::READER);
332
333
                } catch (Exception $e) {
334
335
                    $result = self::generateSyntheticResult($uid, $e->getMessage(), $request->getJid(), false);
336
337
                    // $this->logger->error($result);
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
338
339
                }
340
341
                if ( $request->isChain() ) $this->evalChain($request, $result);
342
343
                $this->updateTrackerSetCompleted($uid, $result);
344
345
                $success = $result->success === false ? "error" : "success";
346
                $this->logger->notice("Task ".$request->getName()."(uid: ".$request->getUid().") ends in $success");
347
348
            } else {
349
350
                $current_time = microtime(true);
351
352
                $request_max_time = $request->getMaxtime();
353
                $maxtime = $request_max_time === null ? $this->max_runtime : $request_max_time;
354
355
                if ( $current_time > $request->getStartTimestamp() + $maxtime ) {
356
357
                    $pid = $request->getPid();
358
359
                    $this->logger->warning("Killing pid $pid due to maximum exec time reached", [
360
                        "START_TIME"    => $request->getStartTimestamp(),
361
                        "CURRENT_TIME"  => $current_time,
362
                        "MAX_RUNTIME"   => $maxtime
363
                    ]);
364
365
                    $kill = ProcessTools::term($pid, $this->lagger_timeout);
366
367
                    if ( $kill ) {
368
                        $this->logger->warning("Pid $pid killed");
369
                    } else {
370
                        $this->logger->warning("Pid $pid could not be killed");
371
                    }
372
373
                    $this->ipc->hang($uid);
374
375
                    $result = self::generateSyntheticResult($uid, "Job killed due to max runtime reached", $request->getJid(), false);
376
377
                    if ( $request->isChain() ) $this->evalChain($request, $result);
378
379
                    $this->updateTrackerSetCompleted($uid, $result);
380
381
                    $this->logger->notice("Task ".$request->getName()."(uid: $uid) ends in error");
382
383
                }
384
385
            }
386
387
        }
388
389
    }
390
391
    private function evalChain(Request $request, Result $result) {
392
393 View Code Duplication
        if ( $result->success && $request->hasOnDone() ) {
0 ignored issues
show
Documentation introduced by
The property success does not exist on object<Comodojo\Extender\Task\Result>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
394
            $chain_done = $request->getOnDone();
395
            $chain_done->getParameters()->set('parent', $result);
396
            $chain_done->setParentUid($result->uid);
0 ignored issues
show
Documentation introduced by
The property uid does not exist on object<Comodojo\Extender\Task\Result>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
397
            $this->add($chain_done);
398
        }
399
400 View Code Duplication
        if ( $result->success === false && $request->hasOnFail() ) {
0 ignored issues
show
Documentation introduced by
The property success does not exist on object<Comodojo\Extender\Task\Result>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
401
            $chain_fail = $request->getOnFail();
402
            $chain_fail->getParameters()->set('parent', $result);
403
            $chain_fail->setParentUid($result->uid);
0 ignored issues
show
Documentation introduced by
The property uid does not exist on object<Comodojo\Extender\Task\Result>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
404
            $this->add($chain_fail);
405
        }
406
407
        if ( $request->hasPipe() ) {
408
            $chain_pipe = $request->getPipe();
409
            $chain_pipe->getParameters()->set('parent', $result);
410
            $chain_pipe->setParentUid($result->uid);
0 ignored issues
show
Documentation introduced by
The property uid does not exist on object<Comodojo\Extender\Task\Result>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
411
            $this->add($chain_pipe);
412
        }
413
414
    }
415
416
    private function generateSyntheticResult($uid, $message, $jid = null, $success = true) {
417
418
        return new Result([
419
            $uid,
420
            null,
421
            $jid,
422
            null,
423
            $success,
424
            null,
425
            null,
426
            $message,
427
            null
428
        ]);
429
430
    }
431
432
    private function updateTrackerSetQueued() {
433
434
        $this->locker->lock([
435
            'QUEUED' => $this->tracker->countQueued()
436
        ]);
437
438
    }
439
440
    private function updateTrackerSetRunning($uid, $pid) {
441
442
        $this->tracker->setRunning($uid, $pid);
443
        $this->locker->lock([
444
            'QUEUED' => $this->tracker->countQueued(),
445
            'RUNNING' => $this->tracker->countRunning()
446
        ]);
447
448
    }
449
450
    private function updateTrackerSetCompleted($uid, $result) {
451
452
        $this->tracker->setCompleted($uid, $result);
453
454
        $lock_data = [
455
            'RUNNING' => $this->tracker->countRunning(),
456
            'COMPLETED' => 1
457
        ];
458
459
        if ( $result->success ) {
460
            $lock_data['SUCCEEDED'] = 1;
461
        } else {
462
            $lock_data['FAILED'] = 1;
463
        }
464
465
        $this->locker->lock($lock_data);
466
467
    }
468
469
    private function updateTrackerSetAborted($uid, $result) {
470
471
        $this->tracker->setAborted($uid, $result);
472
        $lock_data = [
0 ignored issues
show
Unused Code introduced by
$lock_data is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
473
            'RUNNING' => $this->tracker->countRunning(),
474
            'ABORTED' => 1
475
        ];
476
477
    }
478
479
    // private function updateLocker() {
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
480
    //
481
    //     $this->locker->lock([
0 ignored issues
show
Unused Code Comprehensibility introduced by
63% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
482
    //         'QUEUED' => $this->tracker->countQueued(),
0 ignored issues
show
Unused Code Comprehensibility introduced by
62% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
483
    //         'RUNNING' => $this->tracker->countRunning(),
0 ignored issues
show
Unused Code Comprehensibility introduced by
62% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
484
    //         'COMPLETED' => $this->tracker->countCompleted(),
0 ignored issues
show
Unused Code Comprehensibility introduced by
62% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
485
    //         'SUCCEEDED' => $this->tracker->countSucceeded(),
0 ignored issues
show
Unused Code Comprehensibility introduced by
62% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
486
    //         'FAILED' => $this->tracker->countFailed()
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
487
    //     ]);
488
    //
489
    // }
490
491
}
492