feat: skip processing tasks over task quota

This commit is contained in:
Ali BARIN
2023-03-08 20:24:59 +00:00
parent 92d1ed65ff
commit 54e68f6252
5 changed files with 40 additions and 6 deletions

View File

@@ -1,5 +1,6 @@
import { ValidationError } from 'objection';
import type { ModelOptions, QueryContext } from 'objection';
import appConfig from '../config/app';
import ExtendedQueryBuilder from './query-builder';
import Base from './base';
import Step from './step';
@@ -129,6 +130,21 @@ class Flow extends Base {
type: 'trigger',
});
}
async throwIfQuotaExceeded() {
if (!appConfig.isCloud) return;
const user = await this.$relatedQuery('user');
const usageData = await user.$relatedQuery('usageData');
const hasExceeded = await usageData.checkIfLimitExceeded();
if (hasExceeded) {
throw new Error('The allowed task quota has been exhausted!');
}
return this;
}
}
export default Flow;