@param \Pails\Queue\Job             $job
@param \Pails\Queue\ListenerOptions $options

@return mixed
550986
public function process(Job $job, ListenerOptions $options)
    {
        $this->log('[' . get_class($this) . '] MessageId=' . $job->getId() . ', Payload=' . $job->getPayload());

        $res = $this->handle($job, $options);

        $this->log('[' . get_class($this) . '] MessageId=' . $job->getId() . ', Result=' . serialize($res));

        // delete handled job if successfully handled
        if ($res !== false && !$job->isDeleted()) {
            $job->delete();
        }

        return $res;
    }
1058207
protected function invokeCallbacks(AbstractJob $job)
    {
        $result = $job->getResult();

        if ($result->isRedirect() || $result->isRetry()) {
            return $this;
        }

        if ($result->isError()) {
            $callbackJobs = $job->getCallbacksError();
        } else {

            $callbackJobs = $job->getCallbacksDone();
            if($result->isSuccess()){
                $callbackJobs = $callbackJobs + $job->getCallbacksSuccess();
            } else {
                $callbackJobs = $callbackJobs + $job->getCallbacksError();
            }
        }

        if (!is_array($callbackJobs) || count($callbackJobs) === 0) {
            return $this;
        }

        foreach ($callbackJobs as $index => $callbackJob) {
            /** @var $callbackJob AbstractJob */
            $callbackJob($job);
        }

        return $this;
    }
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);
        }
    }
627654
public function push($job, $data = null, $queue = null, $options = [])
    {
        return $this->pushInternal($this->createPayload($job, $data), $queue, $options);
    }
301911
public static function fromJob($job)
    {
        if ($tags = static::extractExplicitTags($job)) {
            return $tags;
        }

        return static::modelsFor(static::targetsFor($job))->map(function ($model) {
            return FormatModel::given($model);
        })->all();
    }
386161
protected function createCommand($connection, $queue, ListenerOptions $options)
    {
        return array_filter([
            $this->phpBinary(),
            $this->artisanBinary(),
            'queue:work',
            $connection,
            '--once',
            "--queue={$queue}",
            "--delay={$options->delay}",
            "--memory={$options->memory}",
            "--sleep={$options->sleep}",
            "--tries={$options->maxTries}",
        ], function ($value) {
            return ! is_null($value);
        });
    }
874471
public function isRunning(Job $job) {
        $runner = $this->getJobRunner($job);

        return $runner->isRunning($job);
    }
129859
public function release(
        Job $job,
        $priority = null,
        $delay = null
    )
    {
        $priority = $priority ?? PheanstalkInterface::DEFAULT_PRIORITY;
        $delay = $delay ?? PheanstalkInterface::DEFAULT_DELAY;

        return $this->client->release($job, $priority, $delay);
    }
617880
public function enqueue(Job $job): void
    {
        $queue = $job->getQueue();

        $this->client->sadd('queue', [$queue]);

        $this->client->rpush(
            sprintf('queue:%s', $queue),
            [
                json_encode($job->getPayload()),
            ]
        );
    }
356062
protected function handleJobException($job, QueueMessage $message, Structure $options, $e)
    {
        if (!$job instanceof JobInterface) {
            $job = new NullJob();
        }

        $this->logger->error(
            sprintf(
                'Job [%s] (%s) failed: %s - Class: %s',
                $job->getName(),
                $message->getId(),
                $e->getMessage(),
                get_class($job)
            )
        );

        if (method_exists($job, 'failed')) {
            $job->failed($e);
        }

        $maxTries = (int) $options->get('tries', 5);

        // Delete and log error if reach max attempts.
        if ($maxTries !== 0 && $maxTries <= $message->getAttempts()) {
            $this->manager->delete($message);
            $this->logger->error(
                sprintf(
                    'Max attempts exceeded. Job: %s (%s) - Class: %s',
                    $job->getName(),
                    $message->getId(),
                    get_class($job)
                )
            );
        }

        $this->dispatcher->triggerEvent(
            'onWorkerJobFailure',
            [
                'worker' => $this,
                'exception' => $e,
                'job' => $job,
                'message' => $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);
    }
850874
private function runJob(JobInterface $job)
    {
        $this->log(LogLevel::DEBUG, 'Job starting');
        $status = $this->executor->execute($job);
        $this->log(LogLevel::DEBUG, 'Job finished');

        return $status;
    }
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);
        }
    }
502250
protected function pauseWorker(ListenerOptions $options, $lastRestart)
    {
        $this->sleep($options->sleep > 0 ? $options->sleep : 1);

        $this->stopIfNecessary($options, $lastRestart);
    }
850463
public function apiSerialize($object, $options = [])
    {
        if (!empty($object)) {
            return $this->serializerProvider->serialize($object, $options);
        }

        return $object;
    }
1240693
protected function timeoutForJob($job, WorkerOptions $options)
    {
        return $job && ! is_null($job->timeout()) ? $job->timeout() : $options->timeout;
    }
526679
public function delete(JobInterface $job)
    {
        if ($job->isRunOnce()) {
            $this->getCache()->delete(self::CACHE_JOB.get_class($job));
        }
        return $job->getBeanstalkJob()->delete();
    }