Total Complexity | 6 |
Total Lines | 77 |
Duplicated Lines | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
18 | class WorkerQuery extends ActiveQuery |
||
19 | { |
||
20 | /** |
||
21 | * @var Env |
||
22 | */ |
||
23 | private $env; |
||
24 | |||
25 | /** |
||
26 | * @param string $modelClass |
||
27 | * @param Env $env |
||
28 | * @param array $config |
||
29 | * @inheritdoc |
||
30 | */ |
||
31 | public function __construct($modelClass, Env $env, array $config = []) |
||
35 | } |
||
36 | |||
37 | /** |
||
38 | * @inheritdoc |
||
39 | */ |
||
40 | public function init() |
||
44 | } |
||
45 | |||
46 | /** |
||
47 | * @param string $host |
||
48 | * @param int $pid |
||
49 | * @return $this |
||
50 | */ |
||
51 | public function byEvent($host, $pid) |
||
56 | ]); |
||
57 | } |
||
58 | |||
59 | /** |
||
60 | * @return $this |
||
61 | */ |
||
62 | public function active() |
||
63 | { |
||
64 | return $this |
||
65 | ->andWhere(['worker.finished_at' => null]) |
||
66 | ->leftJoin(['exec' => ExecRecord::tableName()], '{{exec}}.[[id]] = {{worker}}.[[last_exec_id]]') |
||
67 | ->leftJoin(['push' => PushRecord::tableName()], '{{push}}.[[id]] = {{exec}}.[[push_id]]') |
||
68 | ->andWhere([ |
||
69 | 'or', |
||
70 | ['>', 'worker.pinged_at', time() - $this->env->workerPingInterval - 5], |
||
71 | [ |
||
72 | 'and', |
||
73 | ['is not', 'worker.last_exec_id', null], |
||
74 | ['exec.finished_at' => null], |
||
75 | ], |
||
76 | ]); |
||
77 | } |
||
78 | |||
79 | /** |
||
80 | * @inheritdoc |
||
81 | * @return WorkerRecord[]|array |
||
82 | */ |
||
83 | public function all($db = null) |
||
84 | { |
||
85 | return parent::all($db); |
||
86 | } |
||
87 | |||
88 | /** |
||
89 | * @inheritdoc |
||
90 | * @return WorkerRecord|array|null |
||
91 | */ |
||
92 | public function one($db = null) |
||
95 | } |
||
96 | } |
||
97 |