Cron log method

@param \Extlib\Cron\Adapter\Job\JobInterface $job
@param \Exception $exc
@return \Extlib\Cron
173446
public function log(JobInterface $job ,\Exception $exc)
    {
        if (HistoryInterface::STATUS_WARNING === $exc->getCode()) {
            $this->getAdapter()->history(HistoryInterface::STATUS_WARNING, $job, $exc->getMessage());
        } else {
            $this->getAdapter()->history(HistoryInterface::STATUS_ERROR, $job, $exc->getMessage());
        }
        
        return $this;
    }
243798
private function runJob(CronJob $job, array $jobInfo, OutputInterface $output)
    {
        $output->writeln("-- Starting {$job->id}...");

        // set up the runner
        $class = array_value($jobInfo, 'class');
        $runner = new Runner($job, $class, $this->dispatcher, $this->lockFactory, $this->namespace);
        if ($this->logger) {
            $runner->setLogger($this->logger);
        }

        // set up an object to track this run
        $run = new Run();
        $run->setConsoleOutput($output);

        // and go!
        $runner->go($jobInfo['expires'], $jobInfo['successUrl'], $run);

        if ($run->succeeded()) {
            $output->writeln('-- Success!');
        } elseif (Run::RESULT_LOCKED == $run->getResult()) {
            $output->writeln("{$job->id} is locked!");
        } elseif ($run->failed()) {
            $output->writeln('-- Failed!');
        }

        return $run;
    }
865595
protected function raiseExceptionOccurredJobEvent(Job $job, $e)
    {
        $this->getEventsManager()->fire('listener:jobException', $this, [$job, $e]);
    }
251184
protected function doJob(AbstractJob $job)
    {
        $this->validateJobParams($job);

        try {

            $response = $this->sendMail($job);
            $resultData['response'] = $response;

        } catch (\Exception $ex) {
            throw new ResultException(ResultException::RETRY_TRANSPORT_ERROR);
        }

        if(!$resultData['response']['success']){
            throw new ResultException(ResultException::R_FAILURE, $resultData);
        }

        throw new ResultException(ResultException::R_SUCCESS, $resultData);
    }
87022
public function run(Job $job /*, Callable $callback=null*/) {
        $this->logger->info('Starting Job: '.$job->id.' | '.$job->command);
        $callback = array($this, 'notifyExecutionEnd');

        $runner = $this->getJobRunner($job);

        if ($this->hasDependency($job)) {
            $job_dep = $this->getDependency($job);

            if ($job_dep->exit_code == self::EXIT_CODE_NORMAL && $this->isValid($job_dep)) {
                $this->logger->info('Job has dependency and his dependency is OK | dependency: '.$job_dep->id . ' | '.$job_dep->command);

                $job->status_code = 1;
                $this->execute($job, $runner, $callback);

            } else if ($this->isRunning($job_dep) || $this->isWaiting($job)) {
                $this->logger->info('Job has dependency and his dependency is working | dependency: '.$job_dep->id . ' | '.$job_dep->command);

                $job->status_code = 4;
                $this->execute($job, $runner, $callback);

            } else {
                $this->logger->error('Job has dependency and his dependency get some error, aborting | dependency: '.$job_dep->id . ' | '.$job_dep->command);

                $job->status_code = 2;

            }
        } else {
            $job->status_code = 1;
            $this->execute($job, $runner, $callback);
        }
    }
50644
public function saveJob(Job $job, \Closure $lockCallback = null)
    {
        $class = $this->getEntityRepository()->getClassName();
        if (!$job instanceof $class) {
            throw new \LogicException(sprintf(
                'Got unexpected job instance: expected: "%s", actual" "%s"',
                $class,
                get_class($job)
            ));
        }

        if ($lockCallback) {
            if (!$job->getId()) {
                throw new \LogicException('Is not possible to create new job with lock, only update is allowed');
            }

            $this->getEntityManager()->transactional(function (EntityManager $em) use ($job, $lockCallback) {
                /** @var Job $job */
                $job = $this->getEntityRepository()->find($job->getId(), LockMode::PESSIMISTIC_WRITE);

                $lockCallback($job);

                if ($job->getStoppedAt()) {
                    $this->getEntityManager()->getConnection()->delete($this->uniqueTableName, [
                        'name' => $job->getOwnerId(),
                    ]);

                    if ($job->isUnique()) {
                        $this->getEntityManager()->getConnection()->delete($this->uniqueTableName, [
                            'name' => $job->getName(),
                        ]);
                    }
                }
            });
        } else {
            if (!$job->getId() && $job->isRoot()) {
                // Dbal transaction is used here because Doctrine closes EntityManger any time
                // exception occurs but UniqueConstraintViolationException here is expected here
                // and we should keep EntityManager in open state.
                $this->getEntityManager()->getConnection()->transactional(function (Connection $connection) use ($job) {
                    try {
                        $connection->insert($this->uniqueTableName, [
                            'name' => $job->getOwnerId(),
                        ]);

                        if ($job->isUnique()) {
                            $connection->insert($this->uniqueTableName, [
                                'name' => $job->getName(),
                            ]);
                        }
                    } catch (UniqueConstraintViolationException $e) {
                        throw new DuplicateJobException(sprintf(
                            'Duplicate job. ownerId:"%s", name:"%s"',
                            $job->getOwnerId(),
                            $job->getName()
                        ));
                    }

                    $this->getEntityManager()->persist($job);
                    $this->getEntityManager()->flush();
                });
            } else {
                $this->getEntityManager()->persist($job);
                $this->getEntityManager()->flush();
            }
        }
    }
99054
public function perform(ResqueJobBase $job)
    {
        try {
            $this->resqueInstance->events->trigger('afterFork', $job);
            $result = $job->perform();
            if ($result instanceof \Exception) {
                $this->logger->log(LogLevel::CRITICAL, '{job} has failed {message} at the line {line}',
                    [
                        'job' => $job,
                        'message' => $result->getMessage(),
                        'line' => $result->getLine()
                    ]);
                return;
            }
        } catch (\Exception $e) {
            $this->logger->log(LogLevel::CRITICAL, '{job} has failed {message} at the line {line}',
                [
                    'job' => $job,
                    'message' => $e->getMessage(),
                    'line' => $e->getLine()
                ]);
            return;
        }

        $job->status->update(ResqueJobStatus::STATUS_COMPLETE);
        $this->logger->log(LogLevel::NOTICE, '{job} has finished', ['job' => $job]);
    }
457393
protected function finishJob(Job $job, bool $internal): void
    {
        if ($this->logger) {
            $this->logger->info('Finished a job.', [
                'name' => $job->getName(),
                'arguments' => $job->getArguments(),
            ]);
        }
        if ($this->eventDispatcher) {
            $this->eventDispatcher->dispatch(self::JOB_FINISHED_EVENT, new FinishedJobEvent($job, $internal));
        }
        if ($this->triggerBatchEvents) {
            $this->finishBatch(new JobBatch([], [$job]));
        }
    }
832227
public function add($job, array $config)
    {
        if (empty($config['schedule'])) {
            throw new Exception("'schedule' is required for '$job' job");
        }

        if (!(isset($config['command']) xor isset($config['closure']))) {
            throw new Exception("Either 'command' or 'closure' is required for '$job' job");
        }

        if (isset($config['command']) &&
            (
                $config['command'] instanceof Closure ||
                $config['command'] instanceof SerializableClosure
            )
        ) {
            $config['closure'] = $config['command'];
            unset($config['command']);

            if ($config['closure'] instanceof SerializableClosure) {
                $config['closure'] = $config['closure']->getClosure();
            }
        }

        $config = array_merge($this->config, $config);
        $this->jobs[$job] = $config;
    }
856595
protected function doJob(AbstractJob $job)
    {
        /** @var $job Job */
        $resultData = null;

        try {
            $curl = new CurlWrapper();
            $curl->request($job->getUrl(), $job->getMethod(), $job->getRequestParams());
            $response['content'] = $curl->getResponse();
            $response['info'] = $curl->getTransferInfo();

        } catch (CurlWrapperCurlException $a) {
            $job->addDebug(['CurlWrapperCurlException' => $a->getMessage()]);
            throw new ResultException(ResultException::ERROR_CURL);
        } catch (CurlWrapperException $a) {
            $job->addDebug(['CurlWrapperCurlException' => $a->getMessage()]);
            throw new ResultException(ResultException::ERROR_CURL);
        } catch (\Exception $a) {
            $job->addDebug(['CurlWrapperCurlException' => $a->getMessage()]);
            throw new ResultException(ResultException::ERROR_CURL);
        }

        /**
         * saving data
         */
        if ($job->getSaveContent()) {
            $resultData['content'] = $response['content'];
        }

        if ($job->getSaveInfo()) {
            $resultData['info'] = $response['info'];
        }

        /**
         * analise response
         */
        if ($job->getExpectCode() && $job->getExpectCode() != $response['info']['http_code']) {
            throw new ResultException(ResultException::RETRY_EXPECTED_HTTP_CODE, $resultData);

        } elseif ($job->getExpectContent() && !$this->isContain($job->getExpectContent(), $response['content'])) {
            throw new ResultException(ResultException::RETRY_EXPECTED_CONTENT, $resultData);
        }

        /**
         * success result
         */
        throw new ResultException(ResultException::R_SUCCESS, $resultData);
    }
150967
public function enqueueCron(string $cron, Job $job): void
    {
        $data = ['cron' => $cron, 'job' => $job->getPayload()];

        $id = Uuid::uuid4()->toString();

        $key = sprintf('%s:%s', self::CRON_QUEUE_NAME, $id);

        $this->client->set($key, json_encode($data));

        $this->updateCron($id, $cron);
    }
1010854
public function call(Job $job, array $data)
    {
        try {
            $command = $this->setJobInstanceIfNecessary(
                $job, unserialize($data['command'])
            );
        } catch (ModelNotFoundException $e) {
            $this->handleModelNotFound($job, $e);
            return;
        }

        try {
            $this->dispatcher->dispatchNow($command, $this->resolveHandler($job, $command));
        } catch (\Exception $e) {
            if ($command instanceof ErrorHandler) {
                $command->errorHandle($e);
            }

            throw $e;
        } finally {
            app()->instance('QueueCurrentJob', $command);
        }

        if (!$job->hasFailed() && !$job->isReleased()) {
            $this->ensureNextJobInChainIsDispatched($command);
        }

        if (!$job->isDeletedOrReleased()) {
            $job->delete();
        }
    }
1174697
public function execute(JobInterface $job)
    {
        $data = $job->getData();

        if (!isset($data['callback'])) {
            throw new \InvalidArgumentException('Could not find callback.');
        }

        if (!is_callable($data['callback'])) {
            throw new \InvalidArgumentException('The callback needs to be a callable.');
        }

        $callback = $data['callback'];
        unset($data['callback']);

        return call_user_func($callback, $job->getName(), $data);
    }
632449
public static function onFailure(\Exception $e, \Resque_Job $job)
    {
        /** @var JobBase $failedJob */
        $failedJob = $job->getInstance();
        $failedJob->errorLog('Caught exception in '. get_called_class() . ': ' . $e->getMessage());
        $failedJob->getStat()->increment($failedJob->getStatFailureIncrementKey());
        throw $e;
    }
975237
public function addJob($job = []) {
        if(!isset($job['msg']))
            throw new RuntimeException('Job without a message');

        if(!isset($job['schedule']))
            throw new RuntimeException('Job without a CRON expression');

        if(!isset($job['function']))
            throw new RuntimeException('Job without a function');

        if($this->isDue($job['schedule']))
            $this->jobs[] = $job;
    }
991204
protected function runJob(Job $job, ListenerOptions $options)
    {
        try {
            $this->process($job, $options);
        } catch (Exception $e) {
            $this->exceptions->report($e);
        } catch (Throwable $e) {
            $this->exceptions->report(new FatalThrowableError($e));
        }
    }
1343252
public function perform(Job $job)
    {
        try {
            Event::trigger('afterFork', $job);
            $job->perform();
        } catch(Exception $e) {
            $this->log($job . ' failed: ' . $e->getMessage());
            $job->fail($e);
            return;
        }

        $job->updateStatus(Status::STATUS_COMPLETE);
        $this->log('done ' . $job);
    }