]> _ Git - psq.git/commitdiff
error handling on process pdf file + timeout longer
authorLouis Jeckel <louis.jeckel@outlook.cm>
Mon, 21 Sep 2020 15:07:15 +0000 (17:07 +0200)
committerLouis Jeckel <louis.jeckel@outlook.cm>
Mon, 21 Sep 2020 15:07:15 +0000 (17:07 +0200)
app/Events/FileProcessingUpdate.php
app/Jobs/ProcessPdfFile.php
app/PdfFile.php
config/horizon.php
config/queue.php
public/admin/js/admin.js
public/js/app.js
resources/js/components/Publish/Step1UploadFile.vue
routes/channels.php

index 7cc2d03c00770135a68cc9f6d9cf217f2a52be4f..7f05e162082c5e1d2846db734a228db8755ee820 100644 (file)
@@ -23,12 +23,12 @@ class FileProcessingUpdate implements ShouldBroadcast
     protected $file;
     public $data;
 
-    public function __construct(PdfFile $file, $status, $data)
+    public function __construct(PdfFile $file, $status, $data = [])
     {
         $this->file = $file;
         $this->data = [
             'status' => $status,
-            'data' => ['file_id' => $file->id]
+            'data' => array_merge($data, ['file_id' => $file->id])
         ];
     }
 
@@ -39,7 +39,7 @@ class FileProcessingUpdate implements ShouldBroadcast
      */
     public function broadcastOn()
     {
-        return new PrivateChannel('fileProcessingStatus.'.$this->file->slug);
+        return new PrivateChannel('fileProcessingStatus');
     }
 
 
index 7f83b9ea0bdd62112aa9049c9d23a41cb43c9440..613fdce4a1c32a828ea17b2469b86868d5108dd1 100644 (file)
@@ -9,6 +9,7 @@ use Illuminate\Contracts\Queue\ShouldQueue;
 use Illuminate\Foundation\Bus\Dispatchable;
 use Illuminate\Queue\InteractsWithQueue;
 use Illuminate\Queue\SerializesModels;
+use Throwable;
 
 class ProcessPdfFile implements ShouldQueue
 {
@@ -20,6 +21,9 @@ class ProcessPdfFile implements ShouldQueue
 
     public $timeout = 180;
 
+
+
+
     /**
      * Create a new job instance.
      *
@@ -39,8 +43,24 @@ class ProcessPdfFile implements ShouldQueue
     public function handle()
     {
         $this->file->process();
-        event(new FileProcessingUpdate($this->file,'done', [
-            'links' => $this->file->trackedLinks()->pluck('title')
+        event(new FileProcessingUpdate($this->file,'done'));
+    }
+
+    /**
+     * Handle a job failure.
+     *
+     * @param  \Throwable  $exception
+     * @return void
+     */
+    public function failed(Throwable $exception)
+    {
+        event(new FileProcessingUpdate($this->file,'failed', [
+            'error' => $exception->getMessage()
         ]));
+        $this->file->fail();
+
+        report($exception);
+
     }
 }
+
index 22135c9b74b8d205e6b6f909ebd3fbbae01ecc3f..39903811fba73ac5bc1b8b0a941fe99e29f24154 100644 (file)
@@ -583,6 +583,16 @@ class PdfFile extends TwillModel implements Sortable
     }
 
 
+    /**
+     * Sets file as failed and deletes
+     */
+    public function fail()
+    {
+        $this->update(['slug' => "FAILED_$this->slug"]);
+        $this->delete();
+    }
+
+
     /**
      * @return Builder
      */
index 866e3e562151a68c61e5a55fea039c7d936dd197..a4b563e1bab0b2a11e488055b176daeea6b95e19 100644 (file)
@@ -151,7 +151,7 @@ return [
     |
     */
 
-    'memory_limit' => 64,
+    'memory_limit' => 128,
 
     /*
     |--------------------------------------------------------------------------
@@ -182,6 +182,7 @@ return [
                 'queue' => ['default'],
                 'balance' => 'simple',
                 'processes' => 3,
+                'timeout' => 600,
                 'tries' => 1,
             ],
         ],
index 00b76d651812116a377978d7bda5df3a48c5f9ba..178d302bd47c77c5ae1185334bd90c92d767bb1c 100644 (file)
@@ -63,7 +63,7 @@ return [
             'driver' => 'redis',
             'connection' => 'default',
             'queue' => env('REDIS_QUEUE', 'default'),
-            'retry_after' => 90,
+            'retry_after' => 600,
             'block_for' => null,
         ],
 
index fa47dde60be19243306655f7cbae98ffff497e84..d0e8d08d0c8c282d1d1a7462dd5515cf82f423c7 100644 (file)
@@ -3146,6 +3146,11 @@ __webpack_require__.r(__webpack_exports__);
 //
 //
 //
+//
+//
+//
+//
+//
 
 
 /* harmony default export */ __webpack_exports__["default"] = ({
@@ -3163,6 +3168,7 @@ __webpack_require__.r(__webpack_exports__);
       progressMode: 'determinate',
       csrf: document.querySelectorAll('meta[name="csrf-token"]')[0].content,
       status: 'start',
+      error: '',
       links: [],
       repeaterFields: [{
         name: 'headline-repeater',
@@ -3203,7 +3209,6 @@ __webpack_require__.r(__webpack_exports__);
     uploadedFile: function uploadedFile(file) {
       if (file.success) {
         this.progressMode = 'indeterminate';
-        Echo["private"]("fileProcessingStatus.".concat(file.response.data.slug)).listen('.status.update', this.processStatusUpdate);
       }
     }
   },
@@ -3225,6 +3230,13 @@ __webpack_require__.r(__webpack_exports__);
           });
         });
       }
+
+      if (e.status === 'failed') {
+        this.progressMode = 'determinate';
+        this.status = 'error';
+        this.error = e.data.error;
+        console.error(e.data.error);
+      }
     },
     getNextRef: function getNextRef(collection_id) {
       var collection = this.collections.find(function (c) {
@@ -3253,6 +3265,7 @@ __webpack_require__.r(__webpack_exports__);
   mounted: function mounted() {
     var _this2 = this;
 
+    Echo["private"]("fileProcessingStatus").listen('.status.update', this.processStatusUpdate);
     axios.get('/publish/collections').then(function (d) {
       _this2.collections = d.data.data;
       _this2.file_ref = _this2.getNextRef(1);
@@ -51815,6 +51828,23 @@ var render = function() {
                   _vm._m(1)
                 ]
               )
+            : _vm.status === "error"
+            ? _c(
+                "div",
+                { staticClass: "alert-danger alert", attrs: { role: "alert" } },
+                [
+                  _c("i", { staticClass: "fas fa-exclamation-triangle" }),
+                  _vm._v(" \n                "),
+                  _c("span", [
+                    _c("strong", [
+                      _vm._v(
+                        "Une erreur est survenue lors du traitement du fichier. "
+                      )
+                    ]),
+                    _vm._v(" (" + _vm._s(_vm.error) + ")")
+                  ])
+                ]
+              )
             : _vm._e(),
           _vm._v(" "),
           _vm.status === "done"
index 99cea1c3848d6f7ac6b49c1535cc8935d5e5fe1f..79dd2fbdf27e00c42060bf6d8d5fe2f9c268c2c8 100644 (file)
@@ -8341,6 +8341,11 @@ __webpack_require__.r(__webpack_exports__);
 //
 //
 //
+//
+//
+//
+//
+//
 
 
 /* harmony default export */ __webpack_exports__["default"] = ({
@@ -8358,6 +8363,7 @@ __webpack_require__.r(__webpack_exports__);
       progressMode: 'determinate',
       csrf: document.querySelectorAll('meta[name="csrf-token"]')[0].content,
       status: 'start',
+      error: '',
       links: [],
       repeaterFields: [{
         name: 'headline-repeater',
@@ -8398,7 +8404,6 @@ __webpack_require__.r(__webpack_exports__);
     uploadedFile: function uploadedFile(file) {
       if (file.success) {
         this.progressMode = 'indeterminate';
-        Echo["private"]("fileProcessingStatus.".concat(file.response.data.slug)).listen('.status.update', this.processStatusUpdate);
       }
     }
   },
@@ -8420,6 +8425,13 @@ __webpack_require__.r(__webpack_exports__);
           });
         });
       }
+
+      if (e.status === 'failed') {
+        this.progressMode = 'determinate';
+        this.status = 'error';
+        this.error = e.data.error;
+        console.error(e.data.error);
+      }
     },
     getNextRef: function getNextRef(collection_id) {
       var collection = this.collections.find(function (c) {
@@ -8448,6 +8460,7 @@ __webpack_require__.r(__webpack_exports__);
   mounted: function mounted() {
     var _this2 = this;
 
+    Echo["private"]("fileProcessingStatus").listen('.status.update', this.processStatusUpdate);
     axios.get('/publish/collections').then(function (d) {
       _this2.collections = d.data.data;
       _this2.file_ref = _this2.getNextRef(1);
@@ -81351,6 +81364,23 @@ var render = function() {
                   _vm._m(1)
                 ]
               )
+            : _vm.status === "error"
+            ? _c(
+                "div",
+                { staticClass: "alert-danger alert", attrs: { role: "alert" } },
+                [
+                  _c("i", { staticClass: "fas fa-exclamation-triangle" }),
+                  _vm._v(" \n                "),
+                  _c("span", [
+                    _c("strong", [
+                      _vm._v(
+                        "Une erreur est survenue lors du traitement du fichier. "
+                      )
+                    ]),
+                    _vm._v(" (" + _vm._s(_vm.error) + ")")
+                  ])
+                ]
+              )
             : _vm._e(),
           _vm._v(" "),
           _vm.status === "done"
index bdb08b1613870976ab987a1bf2c5d91b1350c9ed..06f64cfd5592226844e92e2c90b71969db1a9eb4 100644 (file)
                 <i class="fas fa-cogs"></i>
                 <span>Fichier enregistré, <strong>traitement en cours...</strong></span>
             </div>
+
+            <div v-else-if="status === 'error'" class="alert-danger alert" role="alert">
+                    <i class="fas fa-exclamation-triangle"></i>&nbsp;
+                    <span><strong>Une erreur est survenue lors du traitement du fichier. </strong> ({{error}})</span>
+            </div>
             <div v-if="status === 'done'" >
                 <div class="alert-success alert" role="alert">
                     <i class="fas fa-check"></i>&nbsp;
                 progressMode: 'determinate',
                 csrf: document.querySelectorAll('meta[name="csrf-token"]')[0].content,
                 status: 'start',
+                error: '',
                 links: [],
                 repeaterFields: [
                     {
             uploadedFile: function(file){
                 if (file.success){
                     this.progressMode = 'indeterminate';
-                    Echo.private(`fileProcessingStatus.${file.response.data.slug}`)
-                        .listen('.status.update', this.processStatusUpdate)
+
                 }
             },
 
 
                 }
 
+                if(e.status === 'failed') {
+                    this.progressMode = 'determinate';
+                    this.status = 'error';
+                    this.error = e.data.error;
+                    console.error(e.data.error)
+
+                }
+
 
             },
 
             }
         },
         mounted() {
+                    Echo.private(`fileProcessingStatus`)
+            .listen('.status.update', this.processStatusUpdate)
 
             axios.get('/publish/collections').then(d => {
                 this.collections = d.data.data;
index 7a4b3a0de9114254bdb2ea3fe6589d01dc2afca8..32b7cfb1dba5829b802d906b3f2b3ece56cf79d1 100644 (file)
@@ -22,6 +22,13 @@ Broadcast::channel('emailBatch.{batch}', function ($user, $batch) {
    return true;
 }, ['guards' => 'twill_users']);
 
+/**
+ * @deprecated
+ */
 Broadcast::channel('fileProcessingStatus.{file}', function ($user, $batch) {
    return true;
 }, ['guards' => 'twill_users']);
+
+Broadcast::channel('fileProcessingStatus', function ($user) {
+   return true;
+}, ['guards' => 'twill_users']);