1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\queue\file;
use yii\helpers\Console;
use yii\queue\cli\Action;
/**
* Info about queue status.
*
* @author Roman Zhuravlev <zhuravljov@gmail.com>
*/
class InfoAction extends Action
{
/**
* @var Queue
*/
public $queue;
/**
* Info about queue status.
*/
public function run()
{
Console::output($this->format('Jobs', Console::FG_GREEN));
Console::stdout($this->format('- waiting: ', Console::FG_YELLOW));
Console::output($this->getWaitingCount());
Console::stdout($this->format('- delayed: ', Console::FG_YELLOW));
Console::output($this->getDelayedCount());
Console::stdout($this->format('- reserved: ', Console::FG_YELLOW));
Console::output($this->getReservedCount());
Console::stdout($this->format('- done: ', Console::FG_YELLOW));
Console::output($this->getDoneCount());
}
/**
* @return int
*/
protected function getWaitingCount()
{
$data = $this->getIndexData();
return !empty($data['waiting']) ? count($data['waiting']) : 0;
}
/**
* @return int
*/
protected function getDelayedCount()
{
$data = $this->getIndexData();
return !empty($data['delayed']) ? count($data['delayed']) : 0;
}
/**
* @return int
*/
protected function getReservedCount()
{
$data = $this->getIndexData();
return !empty($data['reserved']) ? count($data['reserved']) : 0;
}
/**
* @return int
*/
protected function getDoneCount()
{
$data = $this->getIndexData();
$total = isset($data['lastId']) ? $data['lastId'] : 0;
return $total - $this->getDelayedCount() - $this->getWaitingCount();
}
protected function getIndexData()
{
static $data;
if ($data === null) {
$fileName = $this->queue->path . '/index.data';
if (file_exists($fileName)) {
$data = call_user_func($this->queue->indexDeserializer, file_get_contents($fileName));
} else {
$data = [];
}
}
return $data;
}
}