Mark the given job ID as reserved.

@param \stdClass $job
@return \stdClass
508529
protected function markJobAsReserved($job)
	{
		$job->reserved = 1;
		$job->attempts = $job->attempts + 1;
		$job->reserved_at = $this->getTime();

		$this->database->table($this->table)->where('id', $job->id)->update([
			'reserved' => $job->reserved,
			'reserved_at' => $job->reserved_at,
			'attempts' => $job->attempts,
		]);

		return $job;
	}
225781
protected function createObjectPayload($job)
    {
        return [
            'displayName' => $this->getDisplayName($job),
            'job' => 'Zilf\Queue\CallQueuedHandler@call',
            'maxTries' => $job->tries ?? null,
            'timeout' => $job->timeout ?? null,
            'timeoutAt' => $this->getJobExpiration($job),
            'data' => [
                'commandName' => get_class($job),
                'command' => serialize(clone $job),
            ],
        ];
    }
274274
private function pushFailedJob(Job $job)
    {
        $this->failed_jobs[] = $job;
        $command = $job->getCommand();
        // If callable, log the string Closure
        if (is_callable($command)) {
            $command = \is_string($command) ? $command : 'Closure';
        }
        $output = trim($job->getOutput());
        $this->addSchedulerVerboseOutput("<red>Error</red>:   <white>{$command}</white> → <normal>{$output}</normal>");

        return $job;
    }
1298154
public function runJob(JobDefinition $job)
    {
        $this->output->writeln(
            [
                "\n",
                sprintf(
                    '<info>Running the %s job</info><comment>%s</comment>',
                    $job->getName(),
                    $job->getDescription() !== '' ? " > ".$job->getDescription() : ''
                )
            ]
        );

        foreach ($job->getTasks() as $task) {
            $preTaskEvent = new PreTaskEvent($job, $task);
            $this->dispatcher->dispatch(Event::PRE_TASK, $preTaskEvent);

            if ($preTaskEvent->isPropagationStopped()) {
                continue;
            }

            $service = $this->taskRegistry->findTaskByType($task->getType());
            $this->prepareServiceForTask($service, $task);

            try {
                $service->run($this->output);
            } catch (TaskRuntimeException $e) {
                if (!$task->continueOnError()) {
                    throw $e;
                }

                /** @var FormatterHelper $formatter */
                $formatter = $this->helperSet->get('formatter');
                $this->output->writeln(
                    [
                        '',
                        $formatter->formatBlock(
                            [
                                sprintf('[Warning] Task: %s', $task->getType()),
                                sprintf('%s', $e->getMessage())
                            ],
                            'bg=yellow;fg=black',
                            true
                        ),
                        ''
                    ]
                );
            }
        }
    }
1226908
private function getJobIdsOfIncomingDependencies(Job $job)
    {
        $jobIds = $this->_em->getConnection()
            ->executeQuery('SELECT source_job_id FROM jms_job_dependencies WHERE dest_job_id = :id', ['id' => $job->getId()])
            ->fetchAll(\PDO::FETCH_COLUMN);

        return $jobIds;
    }
1085709
protected function createPayload($job, $data = '', $queue = null)
    {
        if ($job instanceof Closure) {
            $payload = $this->createClosurePayload($job, $data);
        } else if (is_object($job)) {
            $payload = $this->createObjectPayload($job, $data);
        } else {
            $payload = array(
                'job'  => $job,
                'data' => $this->prepareQueueableEntities($data),
            );
        }

        return json_encode($payload);
    }
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;
    }
317409
protected function marshalJob($queue, $job)
    {
        $job = $this->markJobAsReserved($job);

        return new DatabaseJob(
            $this, $job, $this->connectionName, $queue
        );
    }
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();
    }
72948
protected function createPayload($job, $data = '', $queue = null)
	{
		if ($job instanceof Closure)
		{
			return json_encode($this->createClosurePayload($job, $data));
		}
		elseif (is_object($job))
		{
			return json_encode([
				'job' => 'Illuminate\Queue\CallQueuedHandler@call',
				'data' => ['command' => serialize(clone $job)],
			]);
		}

		return json_encode($this->createPlainPayload($job, $data));
	}
1281417
protected function getNextAvailableJob($queue)
    {
        $expiration = Carbon::now()->subSeconds($this->retryAfter)->getTimestamp();
        $sql = 'SELECT * FROM ' . $this->table . ' WHERE queue =\'' . $this->getQueue($queue) . '\' 
                AND (
                        (reserved_at is NULL AND available_at <=' . $this->currentTime() . ')
                        OR 
                        (reserved_at <= ' . $expiration . ')
                    ) 
                order by id asc limit 1 ';

        $job = $this->database->createCommand($sql)->queryOne();

        return $job ? new DatabaseJobRecord((object)$job) : null;
    }
724120
public function submit($job)
    {
        $this->delete($job['id']);

        if (!empty($job['log']['errors'])) {
            file_put_contents($job['log']['errors'], '');
        }

        $this->set($job);
        $this->url->redirect('', array('job_id' => $job['id']));
    }
35859
public function deleteReserved($queue, $job)
    {
        $this->getConnection()->zrem($this->getQueue($queue).':reserved', $job);
    }
453693
public function job($job, $queue = null)
    {
        return $this->call(
            function () use ($job, $queue) {
                $job = is_string($job) ? resolve($job) : $job;

                if ($job instanceof ShouldQueue) {
                    dispatch($job)->onQueue($queue);
                } else {
                    dispatch_now($job);
                }
            }
        )->name(is_string($job) ? $job : get_class($job));
    }
620306
public function call(Job $job, array $data)
    {
        $handler = $this->setJobInstanceIfNecessary(
            $job, $this->container->make($data['class'])
        );

        call_user_func_array(
            array($handler, $data['method']), unserialize($data['data'])
        );

        if (! $job->isDeletedOrReleased()) {
            $job->delete();
        }
    }
681794
protected function markJobAsReserved($id)
	{
		$this->database->table($this->table)->where('id', $id)->update([
			'reserved' => 1, 'reserved_at' => $this->getTime(),
		]);
	}
1189213
public function dispatch(Queueable $job)
    {
        if (isset($job->queue, $job->delay)) {
            return $this->connection->laterOn($job->queue, $job->delay, $job);
        }
        if (isset($job->queue)) {
            return $this->connection->pushOn($job->queue, $job);
        }
        if (isset($job->delay)) {
            return $this->connection->later($job->delay, $job);
        }

        return $this->connection->push($job);
    }