Completed
Pull Request — master (#35)
by
unknown
03:34
created

QueueTask::queueTaskName()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 0
dl 0
loc 10
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * @author Andy Carter
4
 * @license http://www.opensource.org/licenses/mit-license.php The MIT License
5
 */
6
namespace Queue\Shell\Task;
7
8
use Cake\Console\ConsoleIo;
9
use Cake\Console\Shell;
10
use InvalidArgumentException;
11
12
/**
13
 * Queue Task.
14
 *
15
 * Common Queue plugin tasks properties and methods to be extended by custom
16
 * tasks.
17
 */
18
abstract class QueueTask extends Shell implements QueueTaskInterface
19
{
20
21
    /**
22
     *
23
     * @var string
24
     */
25
    public $queueModelClass = 'Queue.QueuedTasks';
26
27
    /**
28
     *
29
     * @var \Queue\Model\Table\QueuedTasksTable
30
     */
31
    public $QueuedTasks;
32
33
    /**
34
     * Timeout for run, after which the Task is reassigned to a new worker.
35
     *
36
     * @var int
37
     */
38
    public $timeout = 120;
39
40
    /**
41
     * Number of times a failed instance of this task should be restarted before giving up.
42
     *
43
     * @var int
44
     */
45
    public $retries = 1;
46
47
    /**
48
     *
49
     * @param \Cake\Console\ConsoleIo|null $io
50
     *            IO
51
     */
52
    public function __construct(ConsoleIo $io = null)
53
    {
54
        parent::__construct($io);
55
56
        $this->loadModel($this->queueModelClass);
57
    }
58
59
    /**
60
     *
61
     * @return string
62
     * @throws \InvalidArgumentException
63
     */
64
    protected function queueTaskName()
65
    {
66
        $class = get_class($this);
67
68
        preg_match('#\\\\Queue(.+)Task$#', $class, $matches);
69
        if (! $matches) {
70
            throw new InvalidArgumentException('Invalid class name: ' . $class);
71
        }
72
73
        return $matches[1];
74
    }
75
}
76