mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-19 20:43:56 +00:00
f8230990f4
This reverts merge request !157
65 lines
2.7 KiB
PHP
65 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace App\Classes\Modules\Jobs\Processors;
|
|
|
|
|
|
use App\Classes\Modules\Jobs\Services\UpdatesJobResult;
|
|
use App\Classes\Modules\Jobs\Services\FetchesJobResult;
|
|
use App\Classes\Exceptions\JobResourceNotFoundException;
|
|
use App\Classes\Modules\Jobs\DataTransferObjects\ListGenericJobObject;
|
|
use App\Classes\Modules\Jobs\DataTransferObjects\UpdateJobResultObject;
|
|
|
|
class UpdateJobResultProcessor
|
|
{
|
|
|
|
/** @var FetchesJobResult */
|
|
private $fetchesJobResult;
|
|
|
|
/** @var UpdatesJobResult */
|
|
private $updatesJobResult;
|
|
|
|
/**
|
|
* UpdateJobResultProcessor constructor.
|
|
* @param FetchesJobResult $fetchesJobResult
|
|
* @param UpdatesJobResult $updatesJobResult
|
|
*/
|
|
public function __construct(FetchesJobResult $fetchesJobResult, UpdatesJobResult $updatesJobResult)
|
|
{
|
|
$this->fetchesJobResult = $fetchesJobResult;
|
|
$this->updatesJobResult = $updatesJobResult;
|
|
}
|
|
|
|
/**
|
|
* @param ListGenericJobObject $listGenericJobObject
|
|
* @param array $resultCurrent
|
|
* @return void
|
|
* @throws \App\Classes\Exceptions\MalformedRequestException
|
|
* @throws \App\Classes\Exceptions\JobResourceNotFoundException
|
|
*/
|
|
public function execute(ListGenericJobObject $listGenericJobObject, $resultCurrent) {
|
|
$jobResultCurrent = $this->fetchesJobResult->execute(['job_id' => $listGenericJobObject->getJobId()]);
|
|
$resultCurrentJson = json_encode($resultCurrent);
|
|
$resultSignatureCurrent = md5($resultCurrentJson);
|
|
|
|
try{
|
|
$jobResultExisting = $this->fetchesJobResult->execute(['request_signature' => $jobResultCurrent->request_signature, 'result_not_null' => true, 'order_by_id_desc' => true]);
|
|
$resultSignatureExisting = $jobResultExisting->result_signature;
|
|
//if($resultSignatureExisting != $resultSignatureCurrent){
|
|
$this->updateJobResult($jobResultCurrent, $resultCurrentJson, $resultSignatureCurrent, $listGenericJobObject->getJobCommandName(), $listGenericJobObject->getJobCommand());
|
|
//}
|
|
} catch (JobResourceNotFoundException $exception){
|
|
$this->updateJobResult($jobResultCurrent, $resultCurrentJson, $resultSignatureCurrent, $listGenericJobObject->getJobCommandName(), $listGenericJobObject->getJobCommand());
|
|
}
|
|
}
|
|
|
|
private function updateJobResult($jobResultCurrent, $resultCurrentJson, $resultSignatureCurrent, $jobCommandName, $jobCommand){
|
|
$updateJobResultObject = new UpdateJobResultObject(
|
|
$resultCurrentJson,
|
|
$resultSignatureCurrent,
|
|
$jobCommandName,
|
|
$jobCommand
|
|
);
|
|
$create = $this->updatesJobResult->execute($jobResultCurrent, $updateJobResultObject);
|
|
}
|
|
}
|