Merge pull request #991 from automatisch/let-extra-executions-go-through-over-quota
feat: don't interrupt execution due to quota
This commit is contained in:
@@ -131,7 +131,7 @@ class Flow extends Base {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async throwIfQuotaExceeded() {
|
async checkIfQuotaExceeded() {
|
||||||
if (!appConfig.isCloud) return;
|
if (!appConfig.isCloud) return;
|
||||||
|
|
||||||
const user = await this.$relatedQuery('user');
|
const user = await this.$relatedQuery('user');
|
||||||
@@ -139,6 +139,18 @@ class Flow extends Base {
|
|||||||
|
|
||||||
const hasExceeded = await usageData.checkIfLimitExceeded();
|
const hasExceeded = await usageData.checkIfLimitExceeded();
|
||||||
|
|
||||||
|
if (hasExceeded) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
async throwIfQuotaExceeded() {
|
||||||
|
if (!appConfig.isCloud) return;
|
||||||
|
|
||||||
|
const hasExceeded = await this.checkIfQuotaExceeded();
|
||||||
|
|
||||||
if (hasExceeded) {
|
if (hasExceeded) {
|
||||||
throw new Error('The allowed task quota has been exhausted!');
|
throw new Error('The allowed task quota has been exhausted!');
|
||||||
}
|
}
|
||||||
|
@@ -1,4 +1,3 @@
|
|||||||
import appConfig from '../config/app';
|
|
||||||
import Step from '../models/step';
|
import Step from '../models/step';
|
||||||
import Flow from '../models/flow';
|
import Flow from '../models/flow';
|
||||||
import Execution from '../models/execution';
|
import Execution from '../models/execution';
|
||||||
@@ -23,10 +22,6 @@ export const processAction = async (options: ProcessActionOptions) => {
|
|||||||
.findById(executionId)
|
.findById(executionId)
|
||||||
.throwIfNotFound();
|
.throwIfNotFound();
|
||||||
|
|
||||||
if (!execution.testRun) {
|
|
||||||
await flow.throwIfQuotaExceeded();
|
|
||||||
}
|
|
||||||
|
|
||||||
const step = await Step.query().findById(stepId).throwIfNotFound();
|
const step = await Step.query().findById(stepId).throwIfNotFound();
|
||||||
|
|
||||||
const $ = await globalVariable({
|
const $ = await globalVariable({
|
||||||
|
@@ -1,4 +1,3 @@
|
|||||||
import appConfig from '../config/app';
|
|
||||||
import Flow from '../models/flow';
|
import Flow from '../models/flow';
|
||||||
import globalVariable from '../helpers/global-variable';
|
import globalVariable from '../helpers/global-variable';
|
||||||
import EarlyExitError from '../errors/early-exit';
|
import EarlyExitError from '../errors/early-exit';
|
||||||
@@ -13,11 +12,6 @@ type ProcessFlowOptions = {
|
|||||||
export const processFlow = async (options: ProcessFlowOptions) => {
|
export const processFlow = async (options: ProcessFlowOptions) => {
|
||||||
const { testRun, flowId } = options;
|
const { testRun, flowId } = options;
|
||||||
const flow = await Flow.query().findById(flowId).throwIfNotFound();
|
const flow = await Flow.query().findById(flowId).throwIfNotFound();
|
||||||
|
|
||||||
if (!testRun) {
|
|
||||||
await flow.throwIfQuotaExceeded();
|
|
||||||
}
|
|
||||||
|
|
||||||
const triggerStep = await flow.getTriggerStep();
|
const triggerStep = await flow.getTriggerStep();
|
||||||
const triggerCommand = await triggerStep.getTriggerCommand();
|
const triggerCommand = await triggerStep.getTriggerCommand();
|
||||||
|
|
||||||
|
@@ -12,6 +12,13 @@ export const worker = new Worker(
|
|||||||
const { flowId } = job.data;
|
const { flowId } = job.data;
|
||||||
|
|
||||||
const flow = await Flow.query().findById(flowId).throwIfNotFound();
|
const flow = await Flow.query().findById(flowId).throwIfNotFound();
|
||||||
|
|
||||||
|
const quotaExceeded = await flow.checkIfQuotaExceeded();
|
||||||
|
|
||||||
|
if (quotaExceeded) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const triggerStep = await flow.getTriggerStep();
|
const triggerStep = await flow.getTriggerStep();
|
||||||
|
|
||||||
const { data, error } = await processFlow({ flowId });
|
const { data, error } = await processFlow({ flowId });
|
||||||
|
Reference in New Issue
Block a user