Example #1
0
 /**
  * {@inheritdoc}
  */
 public function reportBackgroundProcess(JobInterface $job, $process_id)
 {
     if ($job->getQueue() && get_class($job->getQueue()) == get_class($this)) {
         if ($job_id = $job->getQueueId()) {
             if (is_int($process_id) && $process_id > 0) {
                 if ($this->connection->executeFirstCell('SELECT COUNT(`id`) AS "row_count" FROM `' . self::JOBS_TABLE_NAME . '` WHERE `id` = ? AND `reserved_at` IS NOT NULL', $job_id)) {
                     $this->connection->execute('UPDATE `' . self::JOBS_TABLE_NAME . '` SET `process_id` = ? WHERE `id` = ?', $process_id, $job_id);
                 } else {
                     throw new InvalidArgumentException('Job not found or not running');
                 }
             } else {
                 throw new InvalidArgumentException('Process ID is required (a non-negative integer is expected)');
             }
         } else {
             throw new InvalidArgumentException('Only enqueued jobs can report background processes');
         }
     } else {
         throw new InvalidArgumentException('Job does not belong to this queue');
     }
 }