public function registerJob(Schedule_Maintenance_Job $job, $force = false) { if (!empty($this->validJobs) and !in_array($job->getId(), $this->validJobs)) { Logger::info("Skipped job with ID: " . $job->getId() . " because it is not in the valid jobs."); return false; } if (!$job->isLocked() || $force) { $this->jobs[] = $job; $job->lock(); Logger::info("Registered job with ID: " . $job->getId()); return true; } else { Logger::info("Skipped job with ID: " . $job->getId() . " because it is still locked."); } return false; }
/** * Launch a job from the job queue * @param Schedule_Maintenance_Job $job */ protected function launchJob($job) { $pid = pcntl_fork(); if ($pid == -1) { //Problem launching the job Logger::error('Could not launch new job with id [ ' . $job->getId() . ' ], exiting'); return false; } else { if ($pid) { $this->currentJobs[$pid] = $job->getId(); if (isset($this->signalQueue[$pid])) { $this->childSignalHandler(SIGCHLD, $pid, $this->signalQueue[$pid]); unset($this->signalQueue[$pid]); } } else { //Forked child try { Logger::debug("Executing job [ " . $job->getId() . " ] as forked child"); Pimcore_Resource::reset(); $job->execute(); } catch (Exception $e) { Logger::error($e); Logger::error("Failed to execute job with id [ " . $job->getId() . " ] and method [ " . $job->getMethod() . " ]"); } $job->unlock(); Logger::debug("Done with job [ " . $job->getId() . " ]"); exit(0); } } return true; }