Process a given job from the queue.

@param Job             $job
@param ListenerOptions $options

@throws \Throwable
165551
protected function process(Job $job, ListenerOptions $options)
    {
        try {
            // First we will raise the before job event and determine if the job has already ran
            // over the its maximum attempt limit, which could primarily happen if the job is
            // continually timing out and not actually throwing any exceptions from itself.
            $this->raiseBeforeJobEvent($job);

            $this->markJobAsFailedIfAlreadyExceedsMaxAttempts($job, (int) $options->maxTries);

            $res = $this->di->getShared('queue:' . $this->_queue->getName())->process($job, $options);

            $this->raiseAfterJobEvent($job);
        } catch (Exception $e) {
            $this->handleJobException($job, $options, $e);
        } catch (Throwable $e) {
            $this->handleJobException($job, $options, new FatalThrowableError($e));
        }
    }
302050
protected void process(final Job job, final String curQueue) {
        boolean success = false;
        try {
            this.processingJob.set(true);
            if (threadNameChangingEnabled) {
                renameThread("Processing " + curQueue + " since " + System.currentTimeMillis());
            }
            this.listenerDelegate.fireEvent(JOB_PROCESS, this, curQueue, job, null, null, null);
            this.jedis.set(key(WORKER, this.name), statusMsg(curQueue, job));
            final Object instance = this.jobFactory.materializeJob(job);
            final Object result = execute(job, curQueue, instance);
            success(job, instance, result, curQueue);
            success = true;
        } catch (Throwable thrwbl) {
            failure(thrwbl, job, curQueue);
        } finally {
            removeInFlight(curQueue, success);
            this.jedis.del(key(WORKER, this.name));
            this.processingJob.set(false);
        }
    }
14887
public function push($job, $delay = 0, $queue = null, array $options = [])
    {
        $message = $this->getMessageByJob($job);
        $message->setDelay($delay);
        $message->setQueueName($queue);
        $message->setOptions($options);

        return $this->driver->push($message);
    }
685184
public function queue(string $queueName, JobInterface $job, array $options = []): void
    {
        $queue = $this->queueManager->getQueue($queueName);

        $payload = serialize($job);
        $messageId = $queue->submit($payload, $options);
        $this->emitMessageSubmitted($queue, $messageId, $payload, $options);
    }
245089
private function executeJob(Job $job)
    {
        $this->currentJobId = $job->getId();
        $job->setLogger($this->logger);
        $this->logger->notice("Starting job #" . $this->currentJobId);
        
        if (!function_exists('pcntl_fork')) {
            $this->runJob($job);
            return;
        }

        $pid = pcntl_fork();
        if ($pid) {
            pcntl_wait($status);
        } else {
            $this->runJob($job);
            die();
        }
    }
869130
public function process(array &$job)
    {
        $this->job = &$job;

        $options = $this->job['data']['options'];
        $options['limit'] = array($this->job['done'], $this->job['data']['limit']);

        $items = (array) $this->product->getList($options);

        foreach ($items as $product) {
            $data = $this->prepare($product);
            gplcart_file_csv($this->job['data']['file'], $data, $this->job['data']['delimiter']);
        }

        if (empty($items)) {
            $this->job['status'] = false;
            $this->job['done'] = $this->job['total'];
        } else {
            $this->job['done'] += count($items);
        }
    }
4354
private function runAsChild(Job $job): void
    {
        $status = sprintf('Processing ID: %s in %s', $job->getId(), $job->getQueue());
        $this->updateProcLine($status);

        $this->log->info($status);

        $this->job_manager->run($job);

        if ($this->child === 0) {
            exit(0);
        }
    }
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]));
        }
    }
526454
public function perform(Resque_Job $job)
	{
		try {
			Resque_Event::trigger('afterFork', $job);
			$job->perform();
		}
		catch(Exception $e) {
			$this->logger->log(Psr\Log\LogLevel::CRITICAL, '{job} has failed {stack}', array('job' => $job, 'stack' => $e));
			$job->fail($e);
			return;
		}

		$job->updateStatus(Resque_Job_Status::STATUS_COMPLETE);
		$this->logger->log(Psr\Log\LogLevel::NOTICE, '{job} has finished', array('job' => $job));
	}
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);
        }
    }
534085
public function dispatch($event, $options)
    {
        if (! array_key_exists($event, $this->listeners)) {
            // no callbacks given for this event
            return;
        }

        // Iterate through each Listener attached to this event
        // and call it with the given options
        foreach ($this->listeners[$event] as $callable) {
            call_user_func($callable, $options);
        }
    }
484193
protected function doJob(AbstractJob $job)
    {
        $this->validateJobParams($job);

        try {
            $resultData['response'] = $this->sendMessage($job);
        } catch (\Exception $ex) {
            throw new ResultException(ResultException::ERROR_TRANSPORT);
        }

        throw new ResultException(ResultException::R_SUCCESS, $resultData);
    }
1315085
public function process( $connection, Job $job, $maxTries = 0, $delay = 0 )
	{
		if ( $maxTries > 0 && $job->attempts() > $maxTries )
			return $this->logFailedJob( $connection, $job );

		try
		{
			$this->raiseBeforeJobEvent( $connection, $job );

			// First we will fire off the job. Once it is done we will see if it will be
			// automatically deleted after processing and if so we'll fire the delete
			// method on the job. Otherwise, we will just keep on running our jobs.
			$job->fire();

			$this->raiseAfterJobEvent( $connection, $job );

			return ['job' => $job, 'failed' => false];
		}
		catch ( Exception $e )
		{
			$this->handleJobException( $connection, $job, $delay, $e );
		}
		catch ( Throwable $e )
		{
			$this->handleJobException( $connection, $job, $delay, $e );
		}

		return null;
	}
694101
public function listen($connection, $queue, ListenerOptions $options)
    {
        $process = $this->makeProcess($connection, $queue, $options);

        while (true) {
            $this->runProcess($process, $options->memory);
        }
    }
751775
protected function runJob($job, $connection, $maxTries, $delay)
    {
        try {
            return $this->process($connection, $job, $maxTries, $delay);
        }
        catch (Exception $e) {
            $this->handleException($e);
        }
        catch (Throwable $e) {
            $this->handleException(new FatalThrowableError($e));
        }
    }
234736
protected function runJob($job, $connectionName, WorkerOptions $options)
    {
        try {
            $this->process($connectionName, $job, $options);
        } catch (Exception $e) {

            $this->stopWorkerIfLostConnection($e);
        } catch (Throwable $e) {

            $this->stopWorkerIfLostConnection($e);
        }
    }
852491
public function workingOn($job, $queue = null)
    {
        $job->worker = $this;
        $this->currentJob = $job;
        $this->working = true;
        if(isset($job->status)) {
            $job->status->update(ResqueJobStatus::STATUS_RUNNING);
        }
        $data = json_encode([
            'queue' => isset($queue) ? $queue : $job->queue,
            'run_at' => strtotime('now UTC'),
            'payload' => $job->payload
        ]);
        $this->resqueInstance->redis->set($this->workerName() . ':' . $job->worker, $data);
    }