1
|
|
|
<?php |
2
|
|
|
namespace graychen\yii2\queue\backend\models; |
3
|
|
|
|
4
|
|
|
use Yii; |
5
|
|
|
use yii\behaviors\TimestampBehavior; |
6
|
|
|
use yii\db\ActiveRecord; |
7
|
|
|
|
8
|
|
|
class Queue extends ActiveRecord |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* @inheritdoc |
12
|
|
|
*/ |
13
|
5 |
|
public static function tableName() |
14
|
|
|
{ |
15
|
5 |
|
return '{{%queue}}'; |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @inheritdoc |
20
|
|
|
*/ |
21
|
6 |
|
public function behaviors() |
22
|
|
|
{ |
23
|
|
|
return [ |
24
|
|
|
'timestamp' => [ |
25
|
6 |
|
'class' => TimestampBehavior::className(), |
26
|
|
|
] |
27
|
|
|
]; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @inheritdoc |
32
|
|
|
*/ |
33
|
4 |
|
public function rules() |
34
|
|
|
{ |
35
|
|
|
return [ |
36
|
4 |
|
[['queue_id', 'catalog', 'name', 'description'], 'required'] |
37
|
|
|
]; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @inheritdoc |
42
|
|
|
*/ |
43
|
2 |
|
public function attributeLabels() |
44
|
|
|
{ |
45
|
|
|
return [ |
46
|
2 |
|
'id' => Yii::t('app/queue', 'ID'), |
47
|
2 |
|
'queue_id' => Yii::t('app/queue', '队列id'), |
48
|
2 |
|
'catalog' => Yii::t('app/queue', '类别'), |
49
|
2 |
|
'name' => Yii::t('app/queue', '任务名称'), |
50
|
2 |
|
'description' => Yii::t('app/queue', '详请信息'), |
51
|
2 |
|
'exec_time' => Yii::t('app/queue', '执行时间'), |
52
|
2 |
|
'status' => Yii::t('app/queue', '状态'), |
53
|
2 |
|
'created_at' => Yii::t('app/queue', '队列创建时间'), |
54
|
2 |
|
'updated_at' => Yii::t('app/queue', '队列修改时间'), |
55
|
2 |
|
'execution_time' => Yii::t('app/queue', '队列执行时间') |
56
|
|
|
]; |
57
|
|
|
} |
58
|
|
|
|
59
|
1 |
|
public function getExecutionTime() |
60
|
|
|
{ |
61
|
1 |
|
return $this->exec_time+$this->created_at; |
|
|
|
|
62
|
|
|
} |
63
|
|
|
|
64
|
1 |
|
public function getStatus($id) |
65
|
|
|
{ |
66
|
1 |
|
if (Yii::$app->queue->isWaiting($id) || Yii::$app->queue->isReserved($id)) { |
67
|
1 |
|
$status=0; |
68
|
|
|
} elseif (Yii::$app->queue->isDone($id)) { |
69
|
|
|
$status=1; |
70
|
|
|
} else { |
71
|
|
|
$status=-1; |
72
|
|
|
} |
73
|
1 |
|
return $status; |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
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.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.