committed by
Fredrik Adelöw
parent
ab008a0988
commit
9053686daa
@@ -39,23 +39,16 @@ export class PluginTaskSchedulerImpl implements PluginTaskScheduler {
|
||||
async triggerTask(id: string): Promise<void> {
|
||||
const knex = await this.databaseFactory();
|
||||
|
||||
// get the task definition
|
||||
// check if task exists
|
||||
const rows = await knex<DbTasksRow>(DB_TASKS_TABLE)
|
||||
.select({
|
||||
currentRun: 'current_run_ticket',
|
||||
id: 'id',
|
||||
})
|
||||
.count({ count: '*' })
|
||||
.where('id', '=', id);
|
||||
|
||||
// validate the task exists
|
||||
if (rows.length <= 0 || rows[0].id !== id) {
|
||||
if (rows[0].count !== 1) {
|
||||
throw new NotFoundError(`Task ${id} does not exist`);
|
||||
}
|
||||
|
||||
if (rows[0].currentRun) {
|
||||
throw new ConflictError(`task ${id} is currently running`);
|
||||
}
|
||||
|
||||
const updatedRows = await knex<DbTasksRow>(DB_TASKS_TABLE)
|
||||
.where('id', '=', id)
|
||||
.whereNull('current_run_ticket')
|
||||
|
||||
@@ -15,7 +15,11 @@
|
||||
*/
|
||||
import { buildTechInsightsContext } from './techInsightsContextBuilder';
|
||||
import { createRouter } from './router';
|
||||
import { DatabaseManager, getVoidLogger } from '@backstage/backend-common';
|
||||
import {
|
||||
DatabaseManager,
|
||||
getVoidLogger,
|
||||
PluginDatabaseManager,
|
||||
} from '@backstage/backend-common';
|
||||
import { ConfigReader } from '@backstage/config';
|
||||
import request from 'supertest';
|
||||
import express from 'express';
|
||||
@@ -45,28 +49,21 @@ describe('Tech Insights router tests', () => {
|
||||
});
|
||||
|
||||
beforeAll(async () => {
|
||||
const pluginDatabase: PluginDatabaseManager = {
|
||||
getClient: () => {
|
||||
return Promise.resolve({
|
||||
migrate: {
|
||||
latest: () => {},
|
||||
},
|
||||
}) as unknown as Promise<Knex>;
|
||||
},
|
||||
};
|
||||
const databaseManager: Partial<DatabaseManager> = {
|
||||
forPlugin: () => ({
|
||||
getClient: () => {
|
||||
return Promise.resolve({
|
||||
migrate: {
|
||||
latest: () => {},
|
||||
},
|
||||
}) as unknown as Promise<Knex>;
|
||||
},
|
||||
}),
|
||||
forPlugin: () => pluginDatabase,
|
||||
};
|
||||
const manager = databaseManager as DatabaseManager;
|
||||
const techInsightsContext = await buildTechInsightsContext({
|
||||
database: {
|
||||
getClient: () => {
|
||||
return Promise.resolve({
|
||||
migrate: {
|
||||
latest: () => {},
|
||||
},
|
||||
}) as unknown as Promise<Knex>;
|
||||
},
|
||||
},
|
||||
database: pluginDatabase,
|
||||
logger: getVoidLogger(),
|
||||
factRetrievers: [],
|
||||
scheduler: new TaskScheduler(manager, getVoidLogger()).forPlugin(
|
||||
|
||||
Reference in New Issue
Block a user