feat(api): add get executions endpoint

This commit is contained in:
Ali BARIN
2025-04-24 14:45:39 +00:00
parent 23e9deee90
commit 6ecb05db3e
8 changed files with 347 additions and 5 deletions

View File

@@ -1,3 +1,4 @@
import { DateTime } from 'luxon';
import Base from './base.js';
import Flow from './flow.js';
import ExecutionStep from './execution-step.js';
@@ -40,6 +41,49 @@ class Execution extends Base {
},
});
static find({ name, status, startDateTime, endDateTime }) {
return this.query()
.withSoftDeleted()
.joinRelated({
flow: true,
})
.withGraphFetched({
flow: {
steps: true,
},
})
.where((builder) => {
builder.withSoftDeleted();
if (name) {
builder.where('flow.name', 'ilike', `%${name}%`);
}
if (status === 'success') {
builder.where('executions.status', 'success');
} else if (status === 'failure') {
builder.where('executions.status', 'failure');
}
if (startDateTime) {
const startDate = DateTime.fromMillis(Number(startDateTime));
if (startDate.isValid) {
builder.where('executions.created_at', '>=', startDate.toISO());
}
}
if (endDateTime) {
const endDate = DateTime.fromMillis(Number(endDateTime));
if (endDate.isValid) {
builder.where('executions.created_at', '<=', endDate.toISO());
}
}
})
.orderBy('created_at', 'desc');
}
async $afterInsert(queryContext) {
await super.$afterInsert(queryContext);
Telemetry.executionCreated(this);