/** * {@inheritdoc} */ public function checkStuckJobs() { if ($rows = $this->connection->execute('SELECT * FROM `' . self::JOBS_TABLE_NAME . '` WHERE `reserved_at` < ?', date('Y-m-d H:i:s', time() - 3600))) { foreach ($rows as $row) { if ($row['process_id'] > 0) { if ($this->isProcessRunning($row['process_id'])) { continue; // Skip jobs that launched long running background processes } else { $this->dequeue($row['id']); // Process done? Consider the job executed } } else { try { $this->failJob($this->getJobFromRow($row), new RuntimeException('Job stuck for more than an hour')); } catch (Exception $e) { $this->connection->beginWork(); $this->connection->execute('INSERT INTO `' . self::FAILED_JOBS_TABLE_NAME . '` (`type`, `channel`, `data`, `failed_at`, `reason`) VALUES (?, ?, ?, ?, ?)', $row['type'], $row['channel'], $row['data'], date('Y-m-d H:i:s'), $e->getMessage()); $this->dequeue($row['id']); $this->connection->commit(); } } } } }