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); } }