jobId; Cache::put('jobClass' . $jobId, $fullClassName); // Met le nom de la classe en cache $this->jobInstancesByJobId[$jobId] = $jobInstance; } } /** * Get an instance of a job by it's jobId * @param mixed $jobId The ID of the job in the database * @return BrowserJob */ public function getJobInstance($jobId): BrowserJob { try { return $this->jobInstancesByJobId[$jobId]; } catch (Exception $e) { return $this->getNewJobInstance($jobId); } } /** * Create a new instance of a job class * @param int $jobId * @return object */ private function getNewJobInstance(int $jobId): BrowserJob { $jobClass = Cache::get('jobClass' . $jobId); if ($jobClass == null) { // If we don't have the class in cache, we put all of the job in cache $this->indexJobsClassesById(); return $this->jobInstancesByJobId[$jobId]; // indexJobsClassesById() already created an instance of the job } // If we have the class in cache, we create a new instance of it $instance = new $jobClass(); $this->jobInstancesByJobId[$jobId] = $instance; return $instance; } /** * Terminate all jobs * @return void */ public function terminateAll() { foreach ($this->jobInstancesByJobId as $jobInstance) { $jobInstance->terminate(); } } }