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)) { |
68
|
1 |
|
$status = 0; |
69
|
|
|
} elseif (Yii::$app->queue->isReserved($id)) { |
70
|
|
|
$status = 2; |
71
|
|
|
} elseif (Yii::$app->queue->isDone($id)) { |
72
|
|
|
$status = 1; |
73
|
|
|
} else { |
74
|
|
|
$status = -1; |
75
|
|
|
} |
76
|
1 |
|
return $status; |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.