Scaffolder: Make Close stale tasks default
Signed-off-by: OscarDHdz <v-ohernandez@expediagroup.com>
This commit is contained in:
@@ -554,8 +554,6 @@ export interface RouterOptions {
|
||||
// (undocumented)
|
||||
taskBroker?: TaskBroker;
|
||||
// (undocumented)
|
||||
taskStore?: DatabaseTaskStore;
|
||||
// (undocumented)
|
||||
taskWorkers?: number;
|
||||
}
|
||||
|
||||
|
||||
@@ -151,7 +151,6 @@ describe('createRouter', () => {
|
||||
database: createDatabase(),
|
||||
catalogClient,
|
||||
reader: mockUrlReader,
|
||||
taskStore: databaseTaskStore,
|
||||
taskBroker,
|
||||
});
|
||||
app = express().use(router);
|
||||
@@ -751,7 +750,6 @@ data: {"id":1,"taskId":"a-random-id","type":"completion","createdAt":"","body":{
|
||||
database: createDatabase(),
|
||||
catalogClient,
|
||||
reader: mockUrlReader,
|
||||
taskStore: databaseTaskStore,
|
||||
taskBroker,
|
||||
identity: { getIdentity },
|
||||
});
|
||||
|
||||
@@ -69,7 +69,6 @@ export interface RouterOptions {
|
||||
actions?: TemplateAction<any>[];
|
||||
taskWorkers?: number;
|
||||
taskBroker?: TaskBroker;
|
||||
taskStore?: DatabaseTaskStore;
|
||||
additionalTemplateFilters?: Record<string, TemplateFilter>;
|
||||
identity?: IdentityApi;
|
||||
}
|
||||
@@ -171,16 +170,28 @@ export async function createRouter(
|
||||
const workingDirectory = await getWorkingDirectory(config, logger);
|
||||
const integrations = ScmIntegrations.fromConfig(config);
|
||||
|
||||
let databaseTaskStore: DatabaseTaskStore;
|
||||
if (!options.taskStore) {
|
||||
databaseTaskStore = await DatabaseTaskStore.create({ database });
|
||||
} else {
|
||||
databaseTaskStore = options.taskStore;
|
||||
}
|
||||
|
||||
let taskBroker: TaskBroker;
|
||||
if (!options.taskBroker) {
|
||||
const databaseTaskStore = await DatabaseTaskStore.create({ database });
|
||||
taskBroker = new StorageTaskBroker(databaseTaskStore, logger);
|
||||
|
||||
if (scheduler && databaseTaskStore.listStaleTasks) {
|
||||
await scheduler.scheduleTask({
|
||||
id: 'close_stale_tasks',
|
||||
frequency: { cron: '*/5 * * * *' }, // every 5 minutes, also supports Duration
|
||||
timeout: { minutes: 15 },
|
||||
fn: async () => {
|
||||
const { tasks } = await databaseTaskStore.listStaleTasks({
|
||||
timeoutS: 3600,
|
||||
});
|
||||
|
||||
for (const task of tasks) {
|
||||
await databaseTaskStore.shutdownTask(task);
|
||||
logger.info(`Successfully closed stale task ${task.taskId}`);
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
} else {
|
||||
taskBroker = options.taskBroker;
|
||||
}
|
||||
@@ -213,24 +224,6 @@ export async function createRouter(
|
||||
actionsToRegister.forEach(action => actionRegistry.register(action));
|
||||
workers.forEach(worker => worker.start());
|
||||
|
||||
if (scheduler && databaseTaskStore.listStaleTasks) {
|
||||
await scheduler.scheduleTask({
|
||||
id: 'close_stale_tasks',
|
||||
frequency: { cron: '*/5 * * * *' }, // every 5 minutes, also supports Duration
|
||||
timeout: { minutes: 15 },
|
||||
fn: async () => {
|
||||
const { tasks } = await databaseTaskStore.listStaleTasks({
|
||||
timeoutS: 3600,
|
||||
});
|
||||
|
||||
for (const task of tasks) {
|
||||
await databaseTaskStore.shutdownTask(task);
|
||||
logger.info(`Successfully closed stale task ${task.taskId}`);
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
const dryRunner = createDryRunner({
|
||||
actionRegistry,
|
||||
integrations,
|
||||
|
||||
Reference in New Issue
Block a user