Cronario\AbstractWorker::factory PHP Метод

factory() публичный статический Метод

public static factory ( $workerClass ) : mixed | self
$workerClass
Результат mixed | self
    public static function factory($workerClass)
    {
        if (!class_exists($workerClass)) {
            throw new Exception\WorkerException("Worker {$workerClass} is not exists");
        }
        $worker = new $workerClass();
        if (!$worker instanceof AbstractWorker) {
            throw new Exception\WorkerException("Worker {$workerClass} is not instanceof AbstractWorker");
        }
        return $worker;
    }

Usage Example

Пример #1
0
 /**
  * if job is sync then we get worker and try execute job
  * else if job is Async then redirect to other queue
  *
  * REMEMBER: Queue name is equal to Worker class name (through all "Cronario")
  *
  * @param AbstractJob|Job $job
  *
  * @throws ResultException
  * @throws WorkerException
  */
 protected function doJob(AbstractJob $job)
 {
     $gatewayClass = $this->analiseGateway($job);
     if ($job->isSync()) {
         $worker = AbstractWorker::factory($gatewayClass);
         return $worker($job);
     }
     if (!$job->hasAttempt()) {
         throw new ResultException(ResultException::FAILURE_MAX_ATTEMPTS);
     }
     // redirect result for new gateway class
     $job->addDebug(['set_gateway' => $gatewayClass]);
     $job->setWorkerClass($gatewayClass)->save();
     throw new ResultException(ResultException::REDIRECT_GATEWAY_CLASS);
 }
All Usage Examples Of Cronario\AbstractWorker::factory