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