From 1a3ae5af1f9fad7e3a3c4e2c15dc6d1d646f076b Mon Sep 17 00:00:00 2001 From: Damon Kaswell Date: Mon, 21 Nov 2022 17:06:16 -0800 Subject: [PATCH] Refine routes Signed-off-by: Damon Kaswell --- .../src/router/routes.ts | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/plugins/incremental-ingestion-backend/src/router/routes.ts b/plugins/incremental-ingestion-backend/src/router/routes.ts index 8607a4d302..d26ace1de3 100644 --- a/plugins/incremental-ingestion-backend/src/router/routes.ts +++ b/plugins/incremental-ingestion-backend/src/router/routes.ts @@ -85,7 +85,7 @@ export const createIncrementalProviderRouter = async ( }); // Trigger the provider's next action - router.put(PROVIDER_BASE_PATH, async (req, res) => { + router.post(`${PROVIDER_BASE_PATH}/trigger`, async (req, res) => { const { provider } = req.params; const record = await manager.getCurrentIngestionRecord(provider); if (record) { @@ -111,18 +111,19 @@ export const createIncrementalProviderRouter = async ( } }); - // Start a brand-new ingestion cycle for the provider - router.post(PROVIDER_BASE_PATH, async (req, res) => { + // Start a brand-new ingestion cycle for the provider. + // (Cancel's the current run if active, or marks it complete if resting) + router.post(`${PROVIDER_BASE_PATH}/start`, async (req, res) => { const { provider } = req.params; const record = await manager.getCurrentIngestionRecord(provider); if (record) { - await manager.updateByName(provider, { - next_action: 'nothing (done)', - ingestion_completed_at: new Date(), - rest_completed_at: new Date(), - status: 'complete', - }); + const ingestionId = record.id; + if (record.status === 'resting') { + await manager.setProviderComplete(ingestionId); + } else { + await manager.setProviderCanceling(ingestionId); + } res.json({ success: true, message: `${provider}: Next cycle triggered.`,