Store a snapshot for the given job.

@param  string  $job
@return void
541118
protected function storeSnapshotForJob($job)
    {
        $data = $this->baseSnapshotData($key = 'job:'.$job);

        $this->connection()->zadd(
            'snapshot:'.$key, $time = Chronos::now()->getTimestamp(), json_encode([
                'throughput' => $data['throughput'],
                'runtime' => $data['runtime'],
                'time' => $time,
            ])
        );

        $this->connection()->zremrangebyrank(
            'snapshot:'.$key, 0, -25
        );
    }
718927
private function runAsParent(Job $job): void
    {
        $status = sprintf('Forked %s for ID: %s', $this->child, $job->getId());
        $this->updateProcLine($status);

        $this->log->debug(
            $status,
            [
                'type' => 'fork',
                'worker' => $this->worker_name,
                'job_id' => $job->getId(),
            ]
        );

        pcntl_wait($wait_status);
        $exit_status = pcntl_wexitstatus($wait_status);

        if ($exit_status !== 0) {
            $this->job_manager->failJob(
                $job,
                new DirtyExitException(
                    sprintf('Job Exited with exit code %d', $exit_status)
                )
            );
        }
    }
1254720
protected function retryJob($job)
    {
        $this->app['queue']->driver($job->connector)->pushRaw(
            $this->resetAttempts($job->payload), $job->queue
        );
    }
306809
public function serialize(Job $job)
    {
        $attributes = $job->getAttributes();
        $attributes['className'] = get_class($job);
        $attributes['type'] = $job->getType();
        return $attributes;
    }
664755
public function getJobInfo($Job) : void
    {
        $uptimeSeconds = time() - $this->startupTime;
        $uptimeSeconds = ($uptimeSeconds === 0) ? 1 : $uptimeSeconds;
        $avgJobsMin = $this->jobsTotal / ($uptimeSeconds / 60);
        $avgJobsMin = round($avgJobsMin, 2);
        $response = [
            'jobs_total' => $this->jobsTotal,
            'avg_jobs_min' => $avgJobsMin,
            'uptime_seconds' => $uptimeSeconds,
        ];
        $Job->sendData(json_encode($response));
    }
1215659
protected function markJobAsReserved($job)
    {
        $this->database->table($this->table)->where('id', $job->id)->update([
            'reserved_at' => $job->touch(),
            'attempts' => $job->increment(),
        ]);

        return $job;
    }
694518
public function perform(Job $job)
    {
        // Set timeout so as to stop any hanged jobs
        // and turn off displaying errors as it fills
        // up the console
        set_time_limit($this->timeout);
        ini_set('display_errors', 0);

        $job->perform();

        $status = $job->getStatus();

        switch ($status) {
            case Job::STATUS_COMPLETE:
                $this->log('Done job <pop>'.$job.'</pop> in <pop>'.$job->execTimeStr().'</pop>', Logger::INFO);
                break;
            case Job::STATUS_CANCELLED:
                $this->log('Cancelled job <pop>'.$job.'</pop>', Logger::INFO);
                break;

            case Job::STATUS_FAILED:
                $this->log('Job '.$job.' failed: "'.$job->failError().'" in '.$job->execTimeStr(), Logger::ERROR);
                break;
            default:
                $this->log('Unknown job status "('.gettype($status).')'.$status.'" for <pop>'.$job.'</pop>', Logger::WARNING);
                break;
        }
    }
393220
public function put($job, $options = null)
    {
        if ($job instanceof JobInterface) {
            if ($job->isRunOnce()) {
                $cacheKey = self::CACHE_JOB . get_class($job);
                if ($this->getCache()->get($cacheKey) === null) {
                    $expire = $job->getDelay() + $job->getTtr() + 60;
                    $this->getCache()->save($cacheKey, 1, $expire);
                } else {
                    return true;
                }
            }
            $options = [
                'delay' => $job->getDelay(),
                'ttr' => $job->getTtr(),
                'priority' => $job->getPriority()
            ];
        }
        $this->getLogger()->info('Add job ' . json_encode($job));
        return parent::put($job, $options);
    }
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();
        }
    }
58835
protected function persist($object)
    {
        if(!$object->getId()) {
            $object->setId($this->getNextId());
        }
        $key = $this->getHash().$object->getId();
        $content = serialize($object);
        
        $this->getFileManager()->write($key, $content, true);
    }
145956
public function release( $job ) {
		$data  = array(
			'job'         => serialize( $job ),
			'attempts'    => $job->attempts(),
			'reserved_at' => null,
		);
		$where = array(
			'id' => $job->id(),
		);

		if ( $this->database->update( $this->jobs_table, $data, $where ) ) {
			return true;
		}

		return false;
	}
230383
protected function fail($job)
    {
        Queue::getFailLogger()->log($job->getQueue()->getConnectionName(), $job->getQueueName(), $job->getRawBody());
        $job->delete();
    }
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);
        }
    }
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();
        }
    }
672184
public function ack(Job $job)
    {
        assert($job->getId() != null);
        return (int) $this->send(['ACKJOB', $job->getId()]);
    }
1211537
public function executeJob(Job $job)
    {
        // Set proper server
        $connectionKey = $job->connectionKey;
        $this->connections->setCurrentConnection($connectionKey);

        foreach ($job->queue as $key => $task) {
            if ($task->usesStages()) {
                $stage = $task->usesStages() ? $connectionKey->stage : null;
                $this->connections->setStage($stage);
            }

            // Check if the current server can run the task
            if (!$this->connections->getCurrentConnection()->isCompatibleWith($task)) {
                continue;
            }

            // Here we fire the task, save its
            // output and return its status
            $state = $task->fire();
            $this->toOutput($state);

            // If the task didn't finish, display what the error was
            if ($task->wasHalted() || $state === false) {
                $this->explainer->error('The tasks queue was canceled by task "'.$task->getName().'"');

                return false;
            }
        }

        return true;
    }
1111447
public function restore(Snapshot $snapshot) : void
    {
        foreach ($snapshot as [$layer, $params]) {
            if ($layer instanceof Parametric) {
                $layer->restore($params);
            }
        }
    }