Jobs setup
This commit is contained in:
@ -15,7 +15,7 @@ class Job extends Repository
|
||||
{
|
||||
parent::__construct($connection, $logger);
|
||||
$this->setFactory($factory)
|
||||
->setTable('attachments_jobs');
|
||||
->setTable('jobs');
|
||||
}
|
||||
|
||||
protected Factory\Model $factory;
|
||||
@ -98,19 +98,22 @@ CREATE TABLE {$this->getTable()} (
|
||||
public function fetchAllPending(): array
|
||||
{
|
||||
$query = "SELECT a.*
|
||||
FROM {$this->getTable()} a
|
||||
JOIN `jobs_states` b ON b.job_id = a.id
|
||||
FROM `{$this->getTable()}` a
|
||||
JOIN (SELECT s1.* FROM `jobs_states` s1 JOIN (SELECT MAX(id) AS id, job_id FROM `jobs_states` GROUP BY job_id) s2 ON s2.id = s1.id) b ON b.`job_id` = a.`id`
|
||||
WHERE b.`status` = ?";
|
||||
return $this->fetchMany($query);
|
||||
return $this->fetchMany($query, [Emails\Model\State\Job::Pending]);
|
||||
}
|
||||
public function fetchByCommandAndArguments(string $command, string $arguments): \ProVM\Emails\Model\Job
|
||||
public function fetchByCommandAndArguments(string $command, string $arguments): Emails\Model\Job
|
||||
{
|
||||
$query = "SELECT * FROM {$this->getTable()} WHERE `command` = ? AND `arguments` = ?";
|
||||
return $this->fetchOne($query, [$command, $arguments]);
|
||||
}
|
||||
public function fetchPendingByMessage(int $message_id): \ProVM\Emails\Model\Job
|
||||
public function fetchAllPendingByCommand(string $command): array
|
||||
{
|
||||
$query = "SELECT * FROM {$this->getTable()} WHERE `message_id` = ? AND `executed` = 0";
|
||||
return $this->fetchOne($query, [$message_id]);
|
||||
$query = "SELECT a.*
|
||||
FROM `{$this->getTable()}` a
|
||||
JOIN (SELECT s1.* FROM `jobs_states` s1 JOIN (SELECT MAX(id) AS id, job_id FROM `jobs_states` GROUP BY job_id) s2 ON s2.id = s1.id) b ON b.`job_id` = a.`id`
|
||||
WHERE a.`command` = ? AND b.`status` = ?";
|
||||
return $this->fetchMany($query, [$command, Emails\Model\State\Job::Pending]);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user