Merge pull request #986 from automatisch/increase-consumed-task-count
feat: increase consumed task count upon tasks
This commit is contained in:
@@ -1,9 +1,10 @@
|
|||||||
import type { QueryContext } from 'objection';
|
import type { QueryContext } from 'objection';
|
||||||
|
import { IJSONObject } from '@automatisch/types';
|
||||||
|
import appConfig from '../config/app';
|
||||||
import Base from './base';
|
import Base from './base';
|
||||||
import Execution from './execution';
|
import Execution from './execution';
|
||||||
import Step from './step';
|
import Step from './step';
|
||||||
import Telemetry from '../helpers/telemetry';
|
import Telemetry from '../helpers/telemetry';
|
||||||
import { IJSONObject } from '@automatisch/types';
|
|
||||||
|
|
||||||
class ExecutionStep extends Base {
|
class ExecutionStep extends Base {
|
||||||
id!: string;
|
id!: string;
|
||||||
@@ -14,6 +15,7 @@ class ExecutionStep extends Base {
|
|||||||
errorDetails: IJSONObject;
|
errorDetails: IJSONObject;
|
||||||
status: 'success' | 'failure';
|
status: 'success' | 'failure';
|
||||||
step: Step;
|
step: Step;
|
||||||
|
execution?: Execution;
|
||||||
|
|
||||||
static tableName = 'execution_steps';
|
static tableName = 'execution_steps';
|
||||||
|
|
||||||
@@ -57,6 +59,18 @@ class ExecutionStep extends Base {
|
|||||||
async $afterInsert(queryContext: QueryContext) {
|
async $afterInsert(queryContext: QueryContext) {
|
||||||
await super.$afterInsert(queryContext);
|
await super.$afterInsert(queryContext);
|
||||||
Telemetry.executionStepCreated(this);
|
Telemetry.executionStepCreated(this);
|
||||||
|
|
||||||
|
if (appConfig.isCloud) {
|
||||||
|
const execution = await this.$relatedQuery('execution');
|
||||||
|
|
||||||
|
if (!execution.testRun && !this.isFailed) {
|
||||||
|
const flow = await execution.$relatedQuery('flow');
|
||||||
|
const user = await flow.$relatedQuery('user');
|
||||||
|
const usageData = await user.$relatedQuery('usageData');
|
||||||
|
|
||||||
|
await usageData.increaseConsumedTaskCountByOne();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -10,6 +10,7 @@ class Execution extends Base {
|
|||||||
testRun: boolean;
|
testRun: boolean;
|
||||||
internalId: string;
|
internalId: string;
|
||||||
executionSteps: ExecutionStep[];
|
executionSteps: ExecutionStep[];
|
||||||
|
flow?: Flow;
|
||||||
|
|
||||||
static tableName = 'executions';
|
static tableName = 'executions';
|
||||||
|
|
||||||
|
@@ -3,6 +3,7 @@ import type { ModelOptions, QueryContext } from 'objection';
|
|||||||
import ExtendedQueryBuilder from './query-builder';
|
import ExtendedQueryBuilder from './query-builder';
|
||||||
import Base from './base';
|
import Base from './base';
|
||||||
import Step from './step';
|
import Step from './step';
|
||||||
|
import User from './user';
|
||||||
import Execution from './execution';
|
import Execution from './execution';
|
||||||
import Telemetry from '../helpers/telemetry';
|
import Telemetry from '../helpers/telemetry';
|
||||||
|
|
||||||
@@ -15,6 +16,7 @@ class Flow extends Base {
|
|||||||
published_at: string;
|
published_at: string;
|
||||||
remoteWebhookId: string;
|
remoteWebhookId: string;
|
||||||
executions?: Execution[];
|
executions?: Execution[];
|
||||||
|
user?: User;
|
||||||
|
|
||||||
static tableName = 'flows';
|
static tableName = 'flows';
|
||||||
|
|
||||||
@@ -51,6 +53,14 @@ class Flow extends Base {
|
|||||||
to: 'executions.flow_id',
|
to: 'executions.flow_id',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
user: {
|
||||||
|
relation: Base.HasOneRelation,
|
||||||
|
modelClass: User,
|
||||||
|
join: {
|
||||||
|
from: 'flows.user_id',
|
||||||
|
to: 'users.id',
|
||||||
|
},
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
async lastInternalId() {
|
async lastInternalId() {
|
||||||
|
@@ -1,3 +1,4 @@
|
|||||||
|
import { raw } from 'objection';
|
||||||
import Base from './base';
|
import Base from './base';
|
||||||
import User from './user';
|
import User from './user';
|
||||||
|
|
||||||
@@ -31,6 +32,10 @@ class UsageData extends Base {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
async increaseConsumedTaskCountByOne() {
|
||||||
|
return await this.$query().patch({ consumedTaskCount: raw('consumed_task_count + 1') });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default UsageData;
|
export default UsageData;
|
||||||
|
Reference in New Issue
Block a user