| Total Complexity | 6 |
| Total Lines | 72 |
| Duplicated Lines | 0 % |
| Changes | 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() |
||
| 41 | { |
||
| 42 | parent::init(); |
||
| 43 | $this->alias('worker'); |
||
| 44 | } |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @param string $host |
||
| 48 | * @param int $pid |
||
| 49 | * @return $this |
||
| 50 | */ |
||
| 51 | public function byEvent($host, $pid) |
||
| 52 | { |
||
| 53 | return $this->andWhere([ |
||
| 54 | 'worker.host' => $host, |
||
| 55 | 'worker.pid' => $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 | ->andWhere([ |
||
| 68 | 'or', |
||
| 69 | ['>', 'worker.pinged_at', time() - $this->env->workerPingInterval - 5], |
||
| 70 | ['exec.finished_at' => null], |
||
| 71 | ]); |
||
| 72 | } |
||
| 73 | |||
| 74 | /** |
||
| 75 | * @inheritdoc |
||
| 76 | * @return WorkerRecord[]|array |
||
| 77 | */ |
||
| 78 | public function all($db = null) |
||
| 79 | { |
||
| 80 | return parent::all($db); |
||
| 81 | } |
||
| 82 | |||
| 83 | /** |
||
| 84 | * @inheritdoc |
||
| 85 | * @return WorkerRecord|array|null |
||
| 86 | */ |
||
| 87 | public function one($db = null) |
||
| 90 | } |
||
| 91 | } |
||
| 92 |