|
@@ -3,21 +3,24 @@
|
|
|
|
|
|
namespace Flowdat\Export\App\Service;
|
|
|
|
|
|
-use Flowdat\Export\App\Factory\S3Factory;
|
|
|
-use Flowdat\Export\App\Factory\ContentTypeFactory;
|
|
|
+use Flowdat\Export\App\Enum\NotificationEnum;
|
|
|
use Flowdat\Export\App\Factory\ExportFactory;
|
|
|
+use Flowdat\Export\App\Factory\S3Factory;
|
|
|
|
|
|
class OnuService
|
|
|
{
|
|
|
|
|
|
private $requestService;
|
|
|
|
|
|
+ private $notificationService;
|
|
|
+
|
|
|
/**
|
|
|
* OnuService constructor.
|
|
|
*/
|
|
|
public function __construct()
|
|
|
{
|
|
|
$this->requestService = new RequestService();
|
|
|
+ $this->notificationService = new NotificationService();
|
|
|
}
|
|
|
|
|
|
public function exportOnus($data, $headers, $notificationId){
|
|
@@ -79,12 +82,17 @@ class OnuService
|
|
|
$filePathS3 = S3Factory::send($filePath, $fileName, $nomeClienteBucket);
|
|
|
}
|
|
|
|
|
|
- $this->updateNotification($endpointBase, $headers, $notificationId, $filePathS3);
|
|
|
-
|
|
|
unlink($filePath);
|
|
|
+
|
|
|
+ $this->updateNotification($endpointBase, $headers, $notificationId, $filePathS3);
|
|
|
return true;
|
|
|
} catch (\Exception $ex){
|
|
|
echo $ex->getMessage();
|
|
|
+
|
|
|
+ $this->notificationService->update($endpointBase, $notificationId, [
|
|
|
+ 'message' => $ex->getMessage(),
|
|
|
+ 'status' => NotificationEnum::ERROR
|
|
|
+ ], $headers);
|
|
|
}
|
|
|
|
|
|
return true;
|
|
@@ -187,12 +195,19 @@ class OnuService
|
|
|
|
|
|
public function updateNotification($endpointBase, $headers, $notificationId, $filePathS3){
|
|
|
echo "Updating notification with ID ".$notificationId.PHP_EOL;
|
|
|
- $this->requestService->put($endpointBase.'/api/notifications/'.$notificationId, [
|
|
|
- 'message' => 'File finished process',
|
|
|
- 'hasFile' => true,
|
|
|
- 'file' => $filePathS3,
|
|
|
- 'status' => 3
|
|
|
- ], $headers);
|
|
|
- echo "Finished update".PHP_EOL;
|
|
|
+ try {
|
|
|
+ $this->notificationService->update($endpointBase, $notificationId, [
|
|
|
+ 'message' => 'File finished process',
|
|
|
+ 'hasFile' => true,
|
|
|
+ 'file' => $filePathS3,
|
|
|
+ 'status' => NotificationEnum::FINISHED
|
|
|
+ ], $headers);
|
|
|
+ echo "Finished update".PHP_EOL;
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ $this->notificationService->update($endpointBase, $notificationId, [
|
|
|
+ 'message' => $e->getMessage(),
|
|
|
+ 'status' => NotificationEnum::ERROR
|
|
|
+ ], $headers);
|
|
|
+ }
|
|
|
}
|
|
|
}
|