Tell the Employee to work on the given job.
@param \Emphloyer\Job $job
769686
public function work(Job $job)
    {
        if (!$this->isFree()) {
            throw new Exceptions\EmployeeNotFreeException();
        }

        $this->workPid = pcntl_fork();

        if ($this->workPid == -1) {
            throw new Exceptions\ForkFailedException();
        }

        $this->workState = self::BUSY;
        $this->job = $job;

        if ($this->workPid == 0) {
            try {
                $job->perform();
                exit(0);
            } catch (\Throwable $exception) {
                Logger::getLogger()->error('Uncaught exception in Emphloyer Job.', [
                    'job_class' => get_class($job),
                    'job_id' => $job->getId(),
                    'exception_code' => $exception->getCode(),
                    'exception_message' => $exception->getMessage(),
                    'exception_stacktrace' => $exception->getTraceAsString(),
                    'exception' => $exception
                ]);
                exit(1);
            }
        }
    }
1076428
public function enqueueAt(int $at, Job $job)
    {
        $this->adapter->enqueueAt($at, $job);

        $this->getEventManager()->trigger('afterSchedule', $job, ['at' => $at]);
    }
115083
public function add(JobInterface $job)
    {
        if (! $job->getName()) {
            throw new JobException('Add a name to the job.');
        }

        $jobs[$job->getName()] = $job;
    }
589246
protected function workComplete(JobInterface $job)
    {
        $this->setCurrentJob(null);
        $this->getLogger()->debug('Work complete on {job}', array('job' => $job));
    }
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]));
        }
    }
455257
public function workingOn(JobInterface $job)
    {
        if (method_exists($job, 'setWorker')) {
            $job->setWorker($this);
        }

        $this->currentJob = $job;

        $this->resque->getStatusFactory()->forJob($job)->update(Status::STATUS_RUNNING);

        $data = json_encode(array(
            'queue' => $job->getQueue(),
            'run_at' => strftime('%a %b %d %H:%M:%S %Z %Y'),
            'payload' => $job->getPayload()
        ));

        $this->resque->getClient()->set($this->getJobKey(), $data);
    }
307365
protected function validateJobParams(Job $job)
    {
        if (empty($job->getToken())) {
            throw new ResultException(ResultException::ERROR_PARAM_TOKEN);
        }

        if (empty($job->getRoom())) {
            throw new ResultException(ResultException::ERROR_PARAM_ROOM);
        }

        if (empty($job->getFrom())) {
            throw new ResultException(ResultException::ERROR_PARAM_FROM);
        }

        if (empty($job->getMsg())) {
            throw new ResultException(ResultException::ERROR_PARAM_MSG);
        }

    }
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;

    }
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;
    }
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();
        }
    }
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);
    }
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;
    }
958706
public function createJob(Job $job)
	{
		$url = $this->service_url . '/jobs';
		$data = $this->service->prepAndSend($url, array(201, 200), 'PUT', $job->toJSON(), true, 'application/job+json', 'application/job+json');
        return Job::createFromJSON(json_decode($data));
	}
158851
public function process(array &$job)
    {
        $this->job = &$job;
        $this->errors = array();

        if (empty($this->job['data']['sources'][$this->job['done']])) {
            $this->job['status'] = false;
            $this->job['done'] = $this->job['total'];
        } else {
            $this->install();
            $this->job['done']++;
            $this->job['errors'] += $this->countErrors();
        }
    }
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);
        }
    }
605017
public function start(Job $job)
    {
        $jobData = new JobData();

        if ($this->exec) {
            $jobDir = $this->_getJobDirectory($job);
            $logFile = realpath($this->getDirectory()) . '/run.log';
            $lockFile = $this->_lockJob($jobDir);

            if ($lockFile) {
                // $jobdir = str_replace("/", DIRECTORY_SEPARATOR, $jobDir);

                $jobData->lockFile = $lockFile;
                $jobData->job = $job;
                $jobData->jobDir = $jobDir;

                $this->runningJobs[spl_object_hash($job)] = $jobData;

                $data = $job->getData();
                $data['___class'] = get_class($job);

                file_put_contents("$jobDir/in.serialize", serialize($data));

                $cmd = $this->getCmd('"'.realpath(__DIR__ . "/../../bin/AsynchronousJobsRun.php") . "\" $jobDir >> $logFile");
                if (substr(php_uname(), 0, 7) == "Windows") {
                    $WshShell = new \COM("WScript.Shell");
                    $WshShell->Run("$cmd /C dir /S %windir%", 0, false);
                } else {
                    exec($cmd . " &");
                }

            } else {
                $this->pendingJobs[] = $job;
            }
        }else {
            $job->run();
            $job->end($jobData);
        }
    }
1150911
public function edit(JobRequest $request, Job $job)
    {
        return $this->response->title(trans('app.edit') . ' ' . trans('career::job.name'))
            ->view('career::job.edit', true)
            ->data(compact('job'))
            ->output();
    }