/** * Execute job by calling specific class::method * * @param int $scheduledTime * @param int $currentTime * @param string[] $jobConfig * @param Schedule $schedule * @param string $groupId * @return void * @throws \Exception */ protected function _runJob($scheduledTime, $currentTime, $jobConfig, $schedule, $groupId) { $scheduleLifetime = (int) $this->_scopeConfig->getValue('system/cron/' . $groupId . '/' . self::XML_PATH_SCHEDULE_LIFETIME, \Magento\Store\Model\ScopeInterface::SCOPE_STORE); $scheduleLifetime = $scheduleLifetime * self::SECONDS_IN_MINUTE; if ($scheduledTime < $currentTime - $scheduleLifetime) { $schedule->setStatus(Schedule::STATUS_MISSED); throw new \Exception('Too late for the schedule'); } if (!isset($jobConfig['instance'], $jobConfig['method'])) { $schedule->setStatus(Schedule::STATUS_ERROR); throw new \Exception('No callbacks found'); } $model = $this->_objectManager->create($jobConfig['instance']); $callback = [$model, $jobConfig['method']]; if (!is_callable($callback)) { $schedule->setStatus(Schedule::STATUS_ERROR); throw new \Exception(sprintf('Invalid callback: %s::%s can\'t be called', $jobConfig['instance'], $jobConfig['method'])); } $schedule->setExecutedAt(strftime('%Y-%m-%d %H:%M:%S', $this->timezone->scopeTimeStamp()))->save(); try { call_user_func_array($callback, [$schedule]); } catch (\Exception $e) { $schedule->setStatus(Schedule::STATUS_ERROR); throw $e; } $schedule->setStatus(Schedule::STATUS_SUCCESS)->setFinishedAt(strftime('%Y-%m-%d %H:%M:%S', $this->timezone->scopeTimeStamp())); }