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