Cron console log method

@param \Extlib\Cron\Adapter\Job\JobInterface $job
@param int $number
@return \Extlib\Cron
183053
public function console(JobInterface $job, $number)
    {
        echo sprintf(
            '%s. Run task: %s (%s) - %s.', $number, $job->getName(), $job->getTaskClassName(), $job->getDateLastRun()->format(self::DATE_LOG_FORMAT)
        ) . PHP_EOL;

        return $this;
    }
1275154
public function execute(InputInterface $input, OutputInterface $output)
    {
        $this->input  = $input;
        $this->output = $output;
        $logger       = $this->logger;

        Resque_Event::listen(
            'onFailure',
            function ($exception, $job) use ($logger) {
                $logger->error('Error processing job', [
                    'exception' => $exception
                ]);
            }
        );

        if ($input->getOption('shutdown')) {
            $this->shutdownWorkers();
            return;
        }

        $queues = $input->getArgument('queue');
        if (! count($queues)) {
            throw new RuntimeException('Not enough arguments.');
        }

        $count    = $input->getOption('count');
        $interval = $input->getOption('interval');

        if ($output->getVerbosity() === OutputInterface::VERBOSITY_VERBOSE) {
            $logLevel = Resque_Worker::LOG_NORMAL;
        } elseif ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERY_VERBOSE) {
            $logLevel = Resque_Worker::LOG_VERBOSE;
        } else {
            $logLevel = Resque_Worker::LOG_NONE;
        }

        $this->startWorkers($queues, $count, $logLevel, $interval);
    }
893780
protected function executeJob(Job $job)
    {
        $job->setStartDate($this->now);

        $command = 'php bin/console campaignchain:job '.$job->getId().' --env='.$this->getContainer()->get(
                'kernel'
            )->getEnvironment();
        $process = new Process($command);

        $this->logger->info('Executing Job with command: '.$command);
        $process->setTimeout($this->timeout);

        try {
            $process->mustRun();

            $this->logger->info('Process ID: '.$process->getPid());

            $job->setPid($process->getPid());
            $this->em->flush();
        } catch (ProcessFailedException $e) {
            $errMsg = 'Process failed: '.$e->getMessage();

            $this->logger->error($errMsg);
            $this->logger->info(self::LOGGER_MSG_END);

            $job->setPid($process->getPid());
            $job->setStatus(Job::STATUS_ERROR);
            $job->setMessage($errMsg);
            $this->em->flush();
        }
    }
1208990
public function getJobRetryDelay($job)
    {
        if (! method_exists($job, 'retryAfter') && ! isset($job->retryAfter)) {
            return;
        }

        $delay = $job->retryAfter ?? $job->retryAfter();

        return $delay instanceof DateTimeInterface
                        ? $this->secondsUntil($delay) : $delay;
    }
1305218
public function delayed($delay, Job $job)
    {
        return $this->connector->delayed($this->queue, $delay, $job);
    }
490931
public function delete(int $job)
    {
        try {
            $instance = $this->pheanstalk->peek(new JobId($job));

            $this->pheanstalk->delete($instance);

            return response()->json([
                'status' => 'success',
                'message' => 'Successfully deleted Job',
            ]);
        } catch (ServerException $e) {
            return response()->json([
                'status' => 'error',
                'message' => $e->getMessage(),
            ]);
        }
    }
258196
protected function propagateListenerOptions($listener, $job)
    {
        return tap($job, function ($job) use ($listener) {
            $job->tries = $listener->tries ?? null;
            $job->timeout = $listener->timeout ?? null;
            $job->timeoutAt = method_exists($listener, 'retryUntil')
                                ? $listener->retryUntil() : null;
        });
    }
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;
    }
1060443
public function removeJob($job = '')
    {

        if ($job instanceof TaskReposity) {
            $job = $job->buildCommandWithExpression();
        }

        $refrector = new CronEntry();
        $job = $refrector->parse($job);

        $this->getManager()->removeJob($job);

        return $this;
    }
344366
public function jobExists($job = '')
    {
        $process = new Process('crontab -l');
        $process->run();

        $output = ($process->getIncrementalOutput());

        $jobs = array_filter(explode(PHP_EOL, $output), function($line) {
            return '' != trim($line);
        });

        return is_array($jobs) ?  array_search($job, $jobs) : false;
    }
1287895
protected function doJob(AbstractJob $job)
    {
        $this->validateJobParams($job);

        $resultData = SmsWorker::buildResultDataDefault(__NAMESPACE__);

        try {
            $response = $this->send($job);

            $resultData[SmsWorker::P_RESULT_DATA_SUCCESS] = count($response['errors']) == 0;
            $resultData[SmsWorker::P_RESULT_DATA_VENDOR_ID] = $response['vendor_id'];
            $resultData[SmsWorker::P_RESULT_DATA_ERRORS] = $response['errors'];

            $job->addDebug(['vendor_response' => $response]);

        } catch (\Exception $ex) {
            $job->addDebug(['exception' => $ex->getMessage()]);
            throw new ResultException(ResultException::ERROR_TRANSPORT);
        }


        if (false === $resultData[SmsWorker::P_RESULT_DATA_SUCCESS]) {

            if (!$job->isSync()) {
                // redirect result for new root gateway class
                $gatewayClass = static::getConfig(SmsWorker::GATEWAY_DISPATCH_CLASS);
                $job->addDebug(['set_gateway' => $gatewayClass]);
                $job->setWorkerClass($gatewayClass)->save();
                throw new ResultException(ResultException::RETRY_GATEWAY_DISPATCH_CLASS);
            }

            throw new ResultException(ResultException::R_FAILURE, $resultData);
        }

        throw new ResultException(ResultException::R_SUCCESS, $resultData);
    }
600963
public function do_job($job) {

        static $objects;

        if ($objects===null) $objects = array();

        $w = $job->workload();

        $h = $job->handle();

        $job_name = $job->functionName();

        if ($this->prefix) {
            $func = $this->prefix.$job_name;
        } else {
            $func = $job_name;
        }

        if (empty($objects[$job_name]) && !function_exists($func) && !class_exists($func, false)) {

            if (!isset($this->functions[$job_name])) {
                $this->log("Function $func is not a registered job name");
                return;
            }

            require_once $this->functions[$job_name]["path"];

            if (class_exists($func) && method_exists($func, "run")) {

                $this->log("Creating a $func object", GearmanManager::LOG_LEVEL_WORKER_INFO);
                $ns_func = "\\$func";
                $objects[$job_name] = new $ns_func();

            } elseif (!function_exists($func)) {

                $this->log("Function $func not found");
                return;
            }

        }

        $this->log("($h) Starting Job: $job_name", GearmanManager::LOG_LEVEL_WORKER_INFO);

        $this->log("($h) Workload: $w", GearmanManager::LOG_LEVEL_DEBUG);

        $log = array();

        /**
         * Run the real function here
         */
        if (isset($objects[$job_name])) {
            $this->log("($h) Calling object for $job_name.", GearmanManager::LOG_LEVEL_DEBUG);
            $result = $objects[$job_name]->run($job, $log);
        } elseif (function_exists($func)) {
            $this->log("($h) Calling function for $job_name.", GearmanManager::LOG_LEVEL_DEBUG);
            $result = $func($job, $log);
        } else {
            $this->log("($h) FAILED to find a function or class for $job_name.", GearmanManager::LOG_LEVEL_INFO);
        }

        if (!empty($log)) {
            foreach ($log as $l) {

                if (!is_scalar($l)) {
                    $l = explode("\n", trim(print_r($l, true)));
                } elseif (strlen($l) > 256) {
                    $l = substr($l, 0, 256)."...(truncated)";
                }

                if (is_array($l)) {
                    foreach ($l as $ln) {
                        $this->log("($h) $ln", GearmanManager::LOG_LEVEL_WORKER_INFO);
                    }
                } else {
                    $this->log("($h) $l", GearmanManager::LOG_LEVEL_WORKER_INFO);
                }

            }
        }

        $result_log = $result;

        if (!is_scalar($result_log)) {
            $result_log = explode("\n", trim(print_r($result_log, true)));
        } elseif (strlen($result_log) > 256) {
            $result_log = substr($result_log, 0, 256)."...(truncated)";
        }

        if (is_array($result_log)) {
            foreach ($result_log as $ln) {
                $this->log("($h) $ln", GearmanManager::LOG_LEVEL_DEBUG);
            }
        } else {
            $this->log("($h) $result_log", GearmanManager::LOG_LEVEL_DEBUG);
        }

        /**
         * Workaround for PECL bug #17114
         * http://pecl.php.net/bugs/bug.php?id=17114
         */
        $type = gettype($result);
        settype($result, $type);


        $this->job_execution_count++;

        return $result;

    }
1362115
protected function sendCalculateRootJobStatusEvent(Job $job)
    {
        $this->producer->sendCommand(Commands::CALCULATE_ROOT_JOB_STATUS, [
            'jobId' => $job->getId(),
        ]);
    }
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();
        }
    }
578353
protected function findNextJob(): ?Job
    {
        $next_at_timestamp = $this->getNextAtTimestamp();
        $cron_id = $this->getNextCronId();

        if (is_null($cron_id)) {
            return $this->getNextAtJob();
        }

        $next_cron_timestamp = $this->getCronTimestamp($cron_id);

        if ($next_at_timestamp <= $next_cron_timestamp) {
            return $this->getNextAtJob();
        }

        return $this->getNextCronJob();
    }
1246463
private function pushFailedJob(Job $job, Exception $e)
    {
        $this->failedJobs[] = $job;

        $compiled = $job->compile();

        // If callable, log the string Closure
        if (is_callable($compiled)) {
            $compiled = 'Closure';
        }

        $this->addSchedulerVerboseOutput("{$e->getMessage()}: {$compiled}");

        return $job;
    }
1123066
public function run(JobInterface $job)
    {
        parent::run($job);

        if (!($job instanceof MappedJob)) {
            return $this;
        }


        $job->setResult(
            $this->mapper->map(
                $job->getEntityRepository(),
                $job->getMappedClass(),
                $job->getResult()
            )
        );

        // allow chaining
        return $this;
    }