Browse Source

feat: add timeout in workflow settings

Ahmad Kholid 3 năm trước cách đây
mục cha
commit
903c699d2d

+ 11 - 6
src/background/workflow-engine/index.js

@@ -252,9 +252,14 @@ class WorkflowEngine {
       return;
     }
 
-    this.workflowTimeout = setTimeout(() => {
-      if (!this.isDestroyed) this.stop('Workflow stopped because of timeout');
-    }, this.workflow.settings.timeout || 120000);
+    const disableTimeoutKeys = ['delay', 'javascript-code'];
+
+    if (!disableTimeoutKeys.includes(block.name)) {
+      this.workflowTimeout = setTimeout(() => {
+        if (!this.isDestroyed) this.stop('Workflow stopped because of timeout');
+      }, this.workflow.settings.timeout || 120000);
+    }
+
     this.currentBlock = block;
 
     workflowState.update(this.id, this.state);
@@ -273,6 +278,9 @@ class WorkflowEngine {
       handler
         .call(this, block, prevBlockData)
         .then((result) => {
+          clearTimeout(this.workflowTimeout);
+          this.workflowTimeout = null;
+
           if (result.nextBlockId) {
             this.logs.push({
               type: 'success',
@@ -291,9 +299,6 @@ class WorkflowEngine {
             this.dispatchEvent('finish');
             this.destroy('success');
           }
-
-          clearTimeout(this.workflowTimeout);
-          this.workflowTimeout = null;
         })
         .catch((error) => {
           this.logs.push({

+ 22 - 12
src/components/newtab/workflow/WorkflowSettings.vue

@@ -1,16 +1,26 @@
 <template>
-  <p class="font-semibold mb-2">On workflow error</p>
-  <div class="space-x-4">
-    <ui-radio
-      v-for="item in onError"
-      :key="item.id"
-      :model-value="workflow.settings.onError"
-      :value="item.id"
-      class="mr-4"
-      @change="updateWorkflow({ onError: $event })"
-    >
-      {{ item.name }}
-    </ui-radio>
+  <div class="mb-4">
+    <p class="mb-1">On workflow error</p>
+    <div class="space-x-4">
+      <ui-radio
+        v-for="item in onError"
+        :key="item.id"
+        :model-value="workflow.settings.onError"
+        :value="item.id"
+        class="mr-4"
+        @change="updateWorkflow({ onError: $event })"
+      >
+        {{ item.name }}
+      </ui-radio>
+    </div>
+  </div>
+  <div>
+    <p class="mb-1">Workflow timeout (milliseconds)</p>
+    <ui-input
+      :model-value="workflow.settings.timeout"
+      type="number"
+      @change="updateWorkflow({ timeout: +$event })"
+    />
   </div>
 </template>
 <script setup>