protected function executeJob(array $job): bool
    {
        if (!class_exists($job['class'])) {
            throw new InvalidJobException('job class does not exists');
        }

        if (null === $this->container) {
            $instance = new $job['class']();
        } else {
            $instance = $this->container->get($job['class']);
        }

        if (!($instance instanceof JobInterface)) {
            throw new InvalidJobException('job must implement JobInterface');
        }

        $instance
            ->setData($job['data'])
            ->setId($job['_id'])
            ->start();

        $return = $this->updateJob($job, JobInterface::STATUS_DONE);

        $this->db->{$this->scheduler->getEventQueue()}->insertOne([
            'job' => $job['_id'],
            'worker' => $this->id,
            'status' => JobInterface::STATUS_DONE,
            'timestamp' => new UTCDateTime(),
        ]);

        unset($instance);

        return $return;
    }
protected function executeJob(array $job): bool
    {
        if (!class_exists($job['class'])) {
            throw new InvalidJobException('job class does not exists');
        }

        if (null === $this->container) {
            $instance = new $job['class']();
        } else {
            $instance = $this->container->get($job['class']);
        }

        if (!($instance instanceof JobInterface)) {
            throw new InvalidJobException('job must implement JobInterface');
        }

        $instance
            ->setData($job['data'])
            ->setId($job['_id'])
            ->start();

        $return = $this->updateJob($job, JobInterface::STATUS_DONE);

        $this->db->{$this->scheduler->getEventQueue()}->insertOne([
            'job' => $job['_id'],
            'worker' => $this->id,
            'status' => JobInterface::STATUS_DONE,
            'timestamp' => new UTCDateTime(),
        ]);

        unset($instance);

        return $return;
    }
protected function executeJob ( array $ job ) : bool { if ( ! class_exists ( $ job [ 'class' ] ) ) { throw new InvalidJobException ( 'job class does not exists' ) ; } if ( null === $ this -> container ) { $ instance = new $ job [ 'class' ] ( ) ; } else { $ instance = $ this -> container -> get ( $ job [ 'class' ] ) ; } if ( ! ( $ instance instanceof JobInterface ) ) { throw new InvalidJobException ( 'job must implement JobInterface' ) ; } $ instance -> setData ( $ job [ 'data' ] ) -> setId ( $ job [ '_id' ] ) -> start ( ) ; $ return = $ this -> updateJob ( $ job , JobInterface :: STATUS_DONE ) ; $ this -> db -> { $ this -> scheduler -> getEventQueue ( ) } -> insertOne ( [ 'job' => $ job [ '_id' ] , 'worker' => $ this -> id , 'status' => JobInterface :: STATUS_DONE , 'timestamp' => new UTCDateTime ( ) , ] ) ; unset ( $ instance ) ; return $ return ; }
Execute job.
Execute job .