| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- <?php
- namespace ModulesGarden\Servers\ProxmoxVps\Core\Queue;
- class DatabaseQueue implements QueueInterface
- {
- /**
- * @var int
- */
- protected $retryLimit = 100;
- /**
- * @param $job
- * @param string $data
- * @param int $parentId
- * @param null $relType
- * @param null $relId
- * @param null $customId
- */
- public function push($job, $data = '', $parentId = null, $relType = null, $relId = null, $customId = null)
- {
- $model = new \ModulesGarden\Servers\ProxmoxVps\Core\Queue\Models\Job();
- $model->job = $job;
- $model->data = $data;
- $model->parent_id = $parentId;
- $model->rel_type = $relType;
- $model->rel_id = $relId;
- $model->custom_id = $customId;
- $model->save();
- return $model;
- }
- public function pushRaw($payload, $queue = null, array $options = [])
- {
- }
- public function later($delay, $job, $data = '', $queue = null)
- {
- }
- public function pushOn($queue, $job, $data = '')
- {
- }
- public function laterOn($queue, $delay, $job, $data = '')
- {
- }
- /**
- * @return mixed
- */
- public function pop()
- {
- return $this->query()->first();
- }
- /**
- * @return mixed
- */
- public function count()
- {
- return $this->query()->count();
- }
- /**
- * @return \ModulesGarden\Servers\ProxmoxVps\Core\Queue\Models\Job
- */
- protected function query()
- {
- $table = (new\ModulesGarden\Servers\ProxmoxVps\Core\Queue\Models\Job)->getTable();
- $query = \ModulesGarden\Servers\ProxmoxVps\Core\Queue\Models\Job
- ::select("{$table}.*")
- ->leftJoin($table.' as parent', function($join) use($table) {
- $join->on($table.'.parent_id', '=', 'parent.id');
- })
- ->where(function($query) use($table){
- $query->where("{$table}.status", '=', '')
- ->orWhere(function($query) use($table){
- $query->where("{$table}.status", '=', \ModulesGarden\Servers\ProxmoxVps\Core\Queue\Models\Job::STATUS_ERROR);
- $query->whereRaw("{$table}.retry_after < NOW()");
- $query->where("{$table}.retry_count", '<', $this->retryLimit);
- })
- ->orWhere(function($query) use($table){
- $query->where("{$table}.status", '=', \ModulesGarden\Servers\ProxmoxVps\Core\Queue\Models\Job::STATUS_WAITING);
- $query->whereRaw("{$table}.retry_after < NOW()");
- $query->where("{$table}.retry_count", '<', $this->retryLimit);
- });
- })
- ->where(function($query) use($table){
- $query->whereRaw("{$table}.parent_id IS NULL");
- $query->orWhere("parent.status", \ModulesGarden\Servers\ProxmoxVps\Core\Queue\Models\Job::STATUS_FINISHED);
- });
- return $query;
- }
- }
|