Passed
Push — develop ( cd6731...746ed8 )
by Nikolay
05:47 queued 12s
created

WorkerBeanstalkdTidyUp::start()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 8
rs 10
cc 2
nc 2
nop 1
1
<?php
2
/**
3
 * Copyright © MIKO LLC - All Rights Reserved
4
 * Unauthorized copying of this file, via any medium is strictly prohibited
5
 * Proprietary and confidential
6
 * Written by Alexey Portnov, 2 2020
7
 */
8
9
namespace MikoPBX\Core\Workers;
10
require_once 'Globals.php';
11
12
use MikoPBX\Core\System\BeanstalkClient;
13
use MikoPBX\Core\System\Util;
14
use Throwable;
15
16
17
/**
18
 * Class WorkerBeanstalkdTidyUp
19
 *
20
 * Keeps beanstalk tubes clean
21
 *
22
 * @package MikoPBX\Core\Workers
23
 */
24
class WorkerBeanstalkdTidyUp extends WorkerBase
25
{
26
27
    public function start($argv): void
28
    {
29
        $managedCache = $this->di->get('managedCache');
30
        $lastTubesCheck = $managedCache->get('lastTubesCheck');
31
        if ($lastTubesCheck === null){
32
            $client = new BeanstalkClient();
33
            $client->cleanTubes();
34
            $managedCache->set('lastTubesCheck', time(), 600);
35
        }
36
    }
37
38
}
39
40
// Start worker process
41
$workerClassname = WorkerBeanstalkdTidyUp::class;
42
if (isset($argv) && count($argv) > 1) {
43
    cli_set_process_title($workerClassname);
44
    try {
45
        $worker = new $workerClassname();
46
        $worker->start($argv);
47
    } catch (Throwable $e) {
48
        global $errorLogger;
49
        $errorLogger->captureException($e);
50
        Util::sysLogMsg("{$workerClassname}_EXCEPTION", $e->getMessage());
51
    }
52
}