Passed
Pull Request — master (#23)
by Nikolay
09:42 queued 03:08
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
    public function start($argv): void
27
    {
28
        $managedCache = $this->di->get('managedCache');
29
        $lastTubesCheck = $managedCache->get('lastTubesCheck');
30
        if ($lastTubesCheck === null){
31
            $client = new BeanstalkClient();
32
            $client->cleanTubes();
33
            $managedCache->set('lastTubesCheck', time(), 300);
34
        }
35
    }
36
37
}
38
39
// Start worker process
40
$workerClassname = WorkerBeanstalkdTidyUp::class;
41
if (isset($argv) && count($argv) > 1) {
42
    cli_set_process_title($workerClassname);
43
    try {
44
        $worker = new $workerClassname();
45
        $worker->start($argv);
46
    } catch (Throwable $e) {
47
        global $errorLogger;
48
        $errorLogger->captureException($e);
49
        Util::sysLogMsg("{$workerClassname}_EXCEPTION", $e->getMessage());
50
    }
51
}