@param string   $ownerId
@param string   $name
@param callable $runCallback

@throws \Throwable|\Exception if $runCallback triggers an exception

@return mixed
160423
public function runUnique($ownerId, $name, callable $runCallback)
    {
        $rootJob = $this->jobProcessor->findOrCreateRootJob($ownerId, $name, true);
        if (!$rootJob) {
            return;
        }

        $childJob = $this->jobProcessor->findOrCreateChildJob($name, $rootJob);

        if (!$childJob->getStartedAt()) {
            $this->jobProcessor->startChildJob($childJob);
        }

        $jobRunner = new self($this->jobProcessor, $rootJob);

        try {
            $result = call_user_func($runCallback, $jobRunner, $childJob);
        } catch (\Throwable $e) {
            try {
                $this->jobProcessor->failChildJob($childJob);
            } catch (\Throwable $t) {
                throw new OrphanJobException(sprintf(
                    'Job cleanup failed. ID: "%s" Name: "%s"',
                    $childJob->getId(),
                    $childJob->getName()
                ), 0, $e);
            }

            throw $e;
        }

        if (!$childJob->getStoppedAt()) {
            $result
                ? $this->jobProcessor->successChildJob($childJob)
                : $this->jobProcessor->failChildJob($childJob);
        }

        return $result;
    }
1012425
public function create($name, $timeout = null)
    {
        if ($this->isExists($name)) {
            return false;
        }

        try {
            $this->db->insert('Queues', [
                'queue_name' => $name,
                'timeout' => ($timeout === null) ? self::CREATE_TIMEOUT_DEFAULT : (int) $timeout,
            ]);
        } catch (Exception $e) {
            throw new RuntimeException($e->getMessage(), $e->getCode(), $e);
        }

        return true;
    }
1014061
public function getCountsByOwnerId( $ownerId, $config = [] ) {

		$owner = $config[ 'owner' ] ?? false;

		$modelTable	= $this->getModelTable();

		$query = new Query();

		$query->select( [ 'status', 'count(id) as total' ] )
				->from( $modelTable );

		if( $owner ) {

			$query->where( "$modelTable.holderId=$ownerId" )->groupBy( 'status' );
		}
		else {

			$query->where( "$modelTable.createdBy=$ownerId" )->groupBy( 'status' );
		}

		$counts     = $query->all();
		$returnArr  = [];
		$counter    = 0;

		foreach( $counts as $count ) {

			$returnArr[ $count[ 'status' ] ] = $count[ 'total' ];

			$counter += $count[ 'total' ];
		}

		$returnArr[ 'all' ] = $counter;

		return $returnArr;
	}
667000
public function setOwnerType($ownerType)
    {
        $allowed_values = array('eve_server', 'corporation', 'faction', 'character', 'alliance');
        if ((!in_array($ownerType, $allowed_values))) {
            throw new \InvalidArgumentException("Invalid value for 'ownerType', must be one of 'eve_server', 'corporation', 'faction', 'character', 'alliance'");
        }
        $this->container['ownerType'] = $ownerType;

        return $this;
    }
217673
public function check_state($key, $ownerid) {
        if (array_key_exists($key, $this->locks)) {
            // The key is locked and we own it.
            return true;
        }
        $lockfile = $this->get_lock_file($key);
        if (file_exists($lockfile)) {
            // The key is locked and we don't own it.
            return false;
        }
        return null;
    }
528529
public function createRoom($ownerId, $roomName = null)
    {
        $params['owner_id'] = $ownerId;
        if (!empty($roomName)) {
            $params['room_name'] = $roomName;
        }
        $body = json_encode($params);
        try {
            $ret = $this->_transport->send(HttpRequest::POST, $this->_baseURL, $body);
        } catch (\Exception $e) {
            return $e;
        }
        return $ret;
    }
233267
protected static function invokeWithErrorHandler(callable $callback, ...$args)
	{
		if(self::$errorHandler === NULL)
		{
			self::$errorHandler = function ($type, $message, $file, $line) {
				throw new \RuntimeException($message);
			};
		}
		
		set_error_handler(self::$errorHandler);
		
		try
		{
			return $callback(...$args);
		}
		finally
		{
			restore_error_handler();
		}
	}
1341498
public function run(callable $callback, array $argsCollection)
    {
        $this->collector->init();
        $children = [];
        foreach ($argsCollection as $key => $args) {
            $pid = pcntl_fork();
            switch ($pid) {
                case -1:
                    throw new \RuntimeException(sprintf('Unable to fork process %d of %d', $key,
                        count($argsCollection)));
                case 0: // child
                    $this->collector->setValue($key, call_user_func_array($callback, $args));
                    exit(0);
                default: //parent
                    $children[] = $pid;
            }
        }
        foreach ($children as $child) {
            do {
                pcntl_waitpid($child, $status);
            } while (!pcntl_wifexited($status));
        }
        return $this->collector->getValues(array_keys($argsCollection));
    }
53992
public function setCallback(Closure $callback = null)
    {
        if ($this->callback !== null || $callback === null) {
            throw new \RuntimeException("Cannot redeclare this comparer callback.");
        }

        $this->callback = Closure::bind($callback, $this, get_called_class());
    }
226009
public function viewAction($owner, $ownerId)
    {
        /** @var BlockProviderInterface $provider */
        $provider = $this->get('opifer.content.block_provider_pool')->getProvider($owner);
        $object = $provider->getBlockOwner($ownerId);

        /** @var Environment $environment */
        $environment = $this->get('opifer.content.block_environment');
        $environment->setDraft(true)->setObject($object);
        $environment->setBlockMode('manage');

        return $this->render($environment->getView(), $environment->getViewParameters());
    }
572706
public function register(string $name, $callback) : Event
    {
        if (is_null($name)) {
            throw new \RuntimeException(sprintf('Event name cannot be empty in %s', __FUNCTION__));
        }

        if (is_null($callback)) {
            throw new \RuntimeException(sprintf('Empty parameter passed as callback in %s function', __FUNCTION__));
        }

        if (!isset($this->events[$name])) {
            $this->events[$name] = [];
        }

        if (!in_array($callback, $this->events[$name])) {
            $this->events[$name][] = $callback;
        }

        return $this;
    }
881018
public function newAuthorizeRequest($owner, $owner_id, $options)
  {
    return $this->getOAuth()->getAuthServer()
          ->getGrantType('authorization_code')
          ->newAuthoriseRequest($owner, $owner_id, $options);
  }
6050
public function callMiddleware($id, $owner)
    {
        if ($owner->freezed) {
            return $owner;
        }

        $class = get_class($owner);
        foreach ($owner->middleware as $definition) {
            $middleware = make($definition);
            if (!$middleware instanceof MiddlewareContract) {
                throw new InvalidConfigException(sprintf("'%s' is not a valid middleware", get_class($middleware)));
            }

            $result = $middleware->handle($owner);
            if ($result === false) {
                break;
            } elseif ($result instanceof $class) {
                $owner = $result;
            } elseif ($result !== null) {
                throw new InvalidValueException(sprintf(
                    'The return value of %s::handle() should be one of false, null and %s',
                    get_class($middleware), $class
                ));
            }
        }

        $this->bind($id, $owner, true);
        $owner->freeze();

        return $owner;
    }
785165
protected static function runCallback($callback, $args)
    {
        if (!is_array($args)) {
            $args = isset($args) ? array($args) : array();
        }
        return call_user_func_array($callback, $args);
    }
1329761
public void setOwner(Graph<DataT, NodeT> ownerGraph) {
        if (this.ownerGraph != null) {
            throw new RuntimeException("Changing owner graph is not allowed");
        }
        this.ownerGraph = ownerGraph;
    }
369565
public function findOrCreateRootJob($ownerId, $jobName, $unique = false)
    {
        if (!$ownerId) {
            throw new \LogicException('OwnerId must not be empty');
        }

        if (!$jobName) {
            throw new \LogicException('Job name must not be empty');
        }

        $job = $this->jobStorage->createJob();
        $job->setOwnerId($ownerId);
        $job->setStatus(Job::STATUS_NEW);
        $job->setName($jobName);
        $job->setCreatedAt(new \DateTime());
        $job->setStartedAt(new \DateTime());
        $job->setUnique((bool) $unique);

        try {
            $this->saveJob($job);

            return $job;
        } catch (DuplicateJobException $e) {
        }

        return $this->jobStorage->findRootJobByOwnerIdAndJobName($ownerId, $jobName);
    }
1250514
public function callback(string $name, callable $callback): self
    {
        $this->data->callback($name, $callback);
        return $this;
    }