Programming Language PHP

Namespace Oro\Component\MessageQueue\Job

Class Job

Method/Function setData

Total Examples 3

3 code examples of PHP Oro\Component\MessageQueue\Job\Job::setData extracted from open source projects

Was this example useful?
0
                                                    protected function saveJobResult(Job $job, array $data)
    {
        if (!empty($data['errors'])) {
            $errorLogFile = $this->saveToStorageErrorLog($data['errors']);
            if ($errorLogFile) {
                $data['errorLogFile'] = $errorLogFile;
            }
        }

        $job->setData($data);
    }
                                            
Was this example useful?
0
                                                    /**
     * @SuppressWarnings(PHPMD.NPathComplexity)
     * @SuppressWarnings(PHPMD.CyclomaticComplexity)
     */
    private function processJob(
        JobRunner $jobRunner,
        Job $job,
        array $body,
        float $startTimestamp,
        bool &$deleteChunkFile
    ): bool {
        $deleteChunkFile = true;
        $chunkFile = new ChunkFile(
            $body['fileName'],
            $body['fileIndex'],
            $body['firstRecordOffset'],
            $body['sectionName']
        );
        $requestType = new RequestType($body['requestType']);
        $requestType->add(ApiAction::UPDATE_LIST);
        $request = new BatchUpdateRequest(
            $body['version'],
            $requestType,
            $body['operationId'],
            [$body['entityClass']],
            $chunkFile,
            $this->fileManager
        );

        $response = $this->handler->handle($request);

        $jobData = $job->getData();
        if ($body['extra_chunk'] ?? false) {
            $jobData['extra_chunk'] = true;
        }
        $previousAggregateTime = $jobData['summary']['aggregateTime'] ?? 0;
        $jobData['summary'] = [
            'aggregateTime' => $this->processingHelper->calculateAggregateTime(
                $startTimestamp,
                $previousAggregateTime
            ),
            'readCount'     => $response->getSummary()->getReadCount(),
            'writeCount'    => $response->getSummary()->getWriteCount(),
            'errorCount'    => $response->getSummary()->getErrorCount(),
            'createCount'   => $response->getSummary()->getCreateCount(),
            'updateCount'   => $response->getSummary()->getUpdateCount(),
        ];
        $job->setData($jobData);

        if ($response->isRetryAgain()) {
            $this->logger->info(sprintf('The retry requested. Reason: %s', $response->getRetryReason()));
            $retryResult = $this->retryChunk($jobRunner, $job, $body, $chunkFile);
            if ($retryResult) {
                $deleteChunkFile = false;
            }

            return $retryResult;
        }

        if ($response->hasUnexpectedErrors()) {
            return false;
        }

        $rawItems = $response->getData();
        if (!$rawItems) {
            // failed to load data
            return false;
        }

        $processedItemStatuses = $response->getProcessedItemStatuses();
        if (!$processedItemStatuses) {
            // some unexpected errors occurred before processing of loaded data
            return false;
        }

        $result = true;
        if ($this->retryHelper->hasItemsToRetry($rawItems, $processedItemStatuses)) {
            $chunksToRetry = $this->retryHelper->getChunksToRetry($rawItems, $processedItemStatuses);
            if ($chunksToRetry && !$this->processChunksToRetry($jobRunner, $job, $body, $chunkFile, $chunksToRetry)) {
                $result = false;
            }
        }

        $jobData['summary']['aggregateTime'] = $this->processingHelper->calculateAggregateTime(
            $startTimestamp,
            $previousAggregateTime
        );
        $job->setData($jobData);

        return $result;
    }
                                            
Was this example useful?
0
                                                    private function saveOperationIdToJob(int $operationId, Job $rootJob): void
    {
        $data = $rootJob->getData();
        $data['api_operation_id'] = $operationId;
        $rootJob->setData($data);
        $this->jobManager->saveJob($rootJob);
    }