Execute batch request

@return array
17119
public function batchExecute()
    {
        $results = $this->execute(new InvokeSpec($this->units, false))->getResults();

        // Make right order in sequence of results. It's required operation, because JSON-RPC2
        // specification define: "The Response objects being returned from a batch call MAY be returned
        // in any order within the Array. The Client SHOULD match contexts between the set of Request objects and the
        // resulting set of Response objects based on the id member within each Object."

        $callMap = [];
        foreach ($this->units as $index => $unit) {
            /** @var Invoke $unit */
            $callMap[$unit->getRawId()] = $index;
        }

        if (count($results) !== count($this->units)) {
            throw new InvalidResponseException();
        }

        $resultSequence = [];
        foreach ($results as $result) {
            if ($result instanceof Result) {
                /** @var Result $result */
                $resultSequence[ $callMap[$result->getId()] ] = $result->getResult();
            } elseif ($result instanceof Error) {
                /** @var Error $result */
                $resultSequence[ $callMap[$result->getId()] ] = $this->serverErrorMode === self::ERRMODE_EXCEPTION ? $result->getBaseException() : null;
            }
        }
        ksort($resultSequence);
        $this->units = [];

        return $resultSequence;
    }
1243434
public function sendBatchRequest(BatchRequest $request)
    {
        $response = $this->sendRequest($request);

        return new BatchResponse($request, $response);
    }
589525
protected function executeCommand()
    {
        $cmdl = $this->realCommand;

        $this->log('Executing command: ' . $cmdl, $this->logLevel);

        $output = [];
        $return = null;

        if ($this->passthru) {
            passthru($cmdl, $return);
        } else {
            exec($cmdl, $output, $return);
        }

        return [$return, $output];
    }
981923
protected function executeCommand()
    {
        $process = new SymfonyProcess(
            $this->makeCommand(),
            $this->target->workingDir
        );

        $process->run();

        $output = $this->outputToCollection($process->getOutput());

        if ($output->count() == 0) {
            return $output;
        }

        if ($rootItem = $this->target->resource->rootItem) {
            return collect($output[$rootItem]);
        }

        return $output;
    }
1256294
protected function perform()
    {
        $event = new Event(array('curl_multi' => $this));

        while ($this->requests) {
            // Notify each request as polling
            $blocking = $total = 0;
            foreach ($this->requests as $request) {
                ++$total;
                $event['request'] = $request;
                $request->getEventDispatcher()->dispatch(self::POLLING_REQUEST, $event);
                // The blocking variable just has to be non-falsey to block the loop
                if ($request->getParams()->hasKey(self::BLOCKING)) {
                    ++$blocking;
                }
            }
            if ($blocking == $total) {
                // Sleep to prevent eating CPU because no requests are actually pending a select call
                usleep(500);
            } else {
                $this->executeHandles();
            }
        }
    }
811368
protected function executeBatched(GraphQLRequest $request): array
    {
        $results = [];
        do {
            $results[] = $this->graphQL->executeRequest($request);
        } while ($request->advanceBatchIndex());

        return $results;
    }
254045
public function start_batch() {
        return new BatchAPI(
            $this->API_KEY,
            array(
                'API_HOST' => $this->API_HOST,
                'API_PROTO' => $this->API_PROTO,
                'API_PORT' => $this->API_PORT,
                'API_VERSION' => $this->API_VERSION,
                'DEBUG' => $this->DEBUG,
            )
        );
    }
1285497
public function execute()
    {
        $request = $this->request->getCurrentRequest();

        $iTotalRecords = $this->queryBuilder->getTotalRecords();
        $iTotalDisplayRecords = $this->queryBuilder->getTotalDisplayRecords();

        list($data, $objects) = $this->queryBuilder->getData($this->multiple);

        $id_index = array_search('_identifier_', array_keys($this->getFields()));
        $ids = array();

        array_walk($data, function($val, $key) use ($id_index, &$ids) {
            $ids[$key] = $val[$id_index];
        });

        if (!is_null($this->fixedData)) {
            $this->fixedData = array_reverse($this->fixedData);
            foreach ($this->fixedData as $item) {
                array_unshift($data, $item);
            }
        }

        if (!is_null($this->renderer)) {
            array_walk($data, $this->renderer);
        }

        if (!is_null($this->rendererObj)) {
            $this->rendererObj->applyTo($data, $objects);
        }

        if (!empty($this->multiple)) {
            array_walk($data,
                    function($val, $key) use(&$data, $ids) {
                array_unshift($val, sprintf('<input type="checkbox" name="dataTables[actions][]" value="%s" />', $ids[$key]));
                $data[$key] = $val;
            });
        }

        $output = array(
            "draw" => $request->query->getInt('draw'),
            "recordsTotal" => $iTotalRecords,
            "recordsFiltered" => $iTotalDisplayRecords,
            "data" => $data
        );

        return new JsonResponse($output);
    }
513316
protected function emulateBatchResponse(BatchRequest $request)
    {
        $response = [];
        foreach ($request as $req) {
            $response[] = $this->emulateResponse($req);
        }

        return $response;
    }
996136
public function execute() {
        if($this->blocking) {
            return $this->executeBlocking();
        } else {
            return $this->errorCheck(
                curl_multi_exec($this->handle,$active)
            );
        }
    }
898194
public function apiAction() {
        /**
         * Prepare the server. Zend_Json_Server cannot work with batched requests natively,
         * so that's taken care of customly here. Therefore, autoEmitResponse is set to false
         * so the server doesn't print the response directly.
         */
        $server = new Zend_Json_Server();
        $server->setClass('Garp_Content_Manager_Proxy');
        $server->setAutoEmitResponse(false);

        if ($this->getRequest()->isPost()) {
            $post = $this->_getJsonRpcRequest();
            $batch = false;
            $responses = array();
            $requests = Zend_Json::decode($post, Zend_Json::TYPE_ARRAY);
            /**
             * Check if this was a batch request. In that case the array is a plain array of
             * arrays. If not, there will be a 'jsonrpc' key in the root of the array.
             */
            $batch = !array_key_exists('jsonrpc', $requests);
            if (!$batch) {
                $requests = array($requests);
            }
            foreach ($requests as $i => $request) {
                $request = $this->_reformJsonRpcRequest($request);
                $requestJson = Zend_Json::encode($request);
                $requestObj = new Zend_Json_Server_Request();
                $requestObj->loadJson($requestJson);
                $server->setRequest($requestObj);
                /**
                 * Note; response gets returned by reference, resulting in a $responses array
                 * containing all the same items.
                 * That's why clone is used here.
                 */
                $response = clone $server->handle();
                $responses[] = $response;
            }
            $response = $batch ? '[' . implode(',', $responses) . ']' : $responses[0];
        } else {
            $response = $server->getServiceMap();
        }
        $this->_helper->layout->setLayout('json');
        //  filter out escaped slashes, because they're annoying and not necessary.
        $response = str_replace('\/', '/', $response);
        $this->view->response = $response;
    }
388237
public function send_batch_requests($requests){
		$client = new \GuzzleHttp\Client();

		$response = $client->post($this->api_endpoint.'batch', array(
		    'headers' =>  array('Authorization' => 'Token token="'.$this->getAPIKey().'"'),
		    'json' => array( "ops" => $requests, "sequential" => true )
		));

		$result = json_decode($response->getBody());

		return $result;
	}
64193
public function run() {

        foreach ( $this->requests as $request ) {

            if ( isset($request['ERROR_CODE']) && isset($request['ERROR_MESSAGE']) ) {

                $this->logger->warning("Invalid request ".$request['ID']);

                $result = self::packJsonError($request['ERROR_CODE'], $request['ERROR_MESSAGE'], $request['ID']);

                if ( !is_null($result) ) $this->results[] = $result;

            } else {

                try {

                    $this->logger->debug("Serving request ".$request['METHOD']."(".$request['ID'].")");

                    $response = $this->runSingleRequest($request['METHOD'], $request['PARAMETERS']);

                    $result = self::packJsonSuccess($response, $request['ID']);

                } catch (RpcException $re) {

                    $this->logger->warning("Error handling request ".$request['ID'].": ".$re->getMessage());

                    $result = self::packJsonError($re->getCode(), $re->getMessage(), $request['ID']);

                } catch (Exception $e) {

                    $this->logger->error($e->getMessage());

                    throw $e;

                }

                if ( !is_null($result) ) $this->results[] = $result;

            }


        }

        if ( empty($this->results) ) {

            return null;

        } else if ( $this->is_batch_request ) {

            return $this->results;

        } else {

            return $this->results[0];

        }

    }
214148
public function execute() {

		// Register all handles and monitor that
		// all requests are executed
		$handleExecutionCounter = array();

		foreach( $this->httpRequests as $httpRequest ) {
			$httpRequest->setOption( CURLOPT_RETURNTRANSFER, true );
			$handleExecutionCounter[(int)  $httpRequest() ] = true;
			curl_multi_add_handle( $this->handle, $httpRequest() );
		}

		$response = $this->doMakeMultiRequest( $handleExecutionCounter );

		return $response;
	}
643373
public function execute()
    {
        $batch  = $this->getBatch();
        $import = $batch->getVariable('import');

        if (! (isset($import['trackId']) && $import['trackId'])) {
            // Do nothing
            return;
        }

        $tracker     = $this->loader->getTracker();
        $trackEngine = $tracker->getTrackEngine($import['trackId']);
        $trackEngine->updateRoundCount($this->currentUser->getUserLoginId());
        
        // Now cleanup the cache
        $this->cache->clean(\Zend_Cache::CLEANING_MODE_MATCHING_TAG, array('tracks'));
    }
702072
public function execute()
    {
        if (! $this->ch) {
            throw new Exception('Curl request not initiated');
        }

        $statusCode = (int) isset($this->lushOptions['return_status']) ? $this->lushOptions['return_status'] : 200;
        $contentType = isset($this->lushOptions['return_content_type']) ? $this->lushOptions['return_content_type'] : 'text';

        $this->headers['url'] = $this->ch;
        $this->headers['http_code'] = $statusCode;

        $this->executed = true;

        return $this->createResponse($statusCode, $contentType);
    }
393253
public function execute(): string
    {
        $calls  = $this->requestParser->parse($this->requestProvider->getPayload());
        $result = $this->processor->process($calls);

        return $this->responseBuilder->build($result);
    }