From 16dd3ae21f075d11f695d3f07912a946e2c35b39 Mon Sep 17 00:00:00 2001 From: Tsiry Sandratraina Date: Thu, 30 May 2024 01:50:17 +0000 Subject: [PATCH 1/3] fix: resolve issue with duplicated runs entries --- src/server/executor.ts | 10 +++++----- src/server/kv/runs.ts | 26 +++++++++++++++++--------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/server/executor.ts b/src/server/executor.ts index 69bc454..3675bd7 100644 --- a/src/server/executor.ts +++ b/src/server/executor.ts @@ -30,6 +30,7 @@ export default async function run(ctx: Context, actions: Action[], data: Run) { ...data, date: new Date().toISOString(), }); + let run = await ctx.kv.runs.get(data.id); for (const action of actions) { if (!action.enabled) { @@ -61,7 +62,7 @@ export default async function run(ctx: Context, actions: Action[], data: Run) { ); await ctx.kv.runs.save(data.projectId, { - ...data, + ...run!, jobs, }); @@ -107,7 +108,7 @@ export default async function run(ctx: Context, actions: Action[], data: Run) { })); const duration = dayjs().diff(runStart, "milliseconds"); await ctx.kv.runs.save(data.projectId, { - ...data, + ...run!, jobs, status: "FAILURE", duration, @@ -129,15 +130,14 @@ export default async function run(ctx: Context, actions: Action[], data: Run) { })); await ctx.kv.runs.save(data.projectId, { - ...data, + ...run!, jobs, - status: "SUCCESS", }); currentActionIndex += 1; } - const run = await ctx.kv.runs.get(data.id); + run = await ctx.kv.runs.get(data.id); const duration = dayjs().diff(runStart, "milliseconds"); await ctx.kv.runs.save(data.projectId, { ...run!, diff --git a/src/server/kv/runs.ts b/src/server/kv/runs.ts index 12dcbd4..4706181 100644 --- a/src/server/kv/runs.ts +++ b/src/server/kv/runs.ts @@ -11,15 +11,14 @@ export async function save(project: string, data: Run) { } const run = await get(data.id); - await kv.set( - [ - FLUENTCI_KV_PREFIX, - "runs_by_date", - project, - dayjs(_.get(run, "date", data.date)).unix(), - ], - data - ); + + await kv.delete([ + FLUENTCI_KV_PREFIX, + "runs_by_date", + project, + dayjs(_.get(run, "date", data.date)).unix(), + ]); + await kv .atomic() .set([FLUENTCI_KV_PREFIX, "runs", project, data.id], data) @@ -34,6 +33,15 @@ export async function save(project: string, data: Run) { ], data ) + .set( + [ + FLUENTCI_KV_PREFIX, + "runs_by_date", + project, + dayjs(_.get(run, "date", data.date)).unix(), + ], + data + ) .commit(); } From 749cace8f95772f252c0288025071d65cd0ce1b7 Mon Sep 17 00:00:00 2001 From: Tsiry Sandratraina Date: Thu, 30 May 2024 01:51:34 +0000 Subject: [PATCH 2/3] bump version code --- README.md | 2 +- src/consts.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1be0e96..ee3c7dd 100644 --- a/README.md +++ b/README.md @@ -110,7 +110,7 @@ fluentci studio fluentci --help Usage: fluentci [pipeline] [jobs...] -Version: 0.14.5 +Version: 0.14.6 Description: diff --git a/src/consts.ts b/src/consts.ts index 51f02a9..9790f7f 100644 --- a/src/consts.ts +++ b/src/consts.ts @@ -1,6 +1,6 @@ import { dir } from "../deps.ts"; -export const VERSION = "0.14.5"; +export const VERSION = "0.14.6"; export const BASE_URL = "https://api.fluentci.io/v1"; From faff30cb7a3caf589825d5da6a0266adc5e3014d Mon Sep 17 00:00:00 2001 From: Tsiry Sandratraina Date: Thu, 30 May 2024 13:32:03 +0000 Subject: [PATCH 3/3] fix: delete duplicated run --- .gitignore | 3 ++- src/server/kv/runs.ts | 19 +++++++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 7520387..7071fef 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ result -demo* \ No newline at end of file +demo* +kview \ No newline at end of file diff --git a/src/server/kv/runs.ts b/src/server/kv/runs.ts index 4706181..24185e9 100644 --- a/src/server/kv/runs.ts +++ b/src/server/kv/runs.ts @@ -12,13 +12,20 @@ export async function save(project: string, data: Run) { const run = await get(data.id); - await kv.delete([ + const { value: runDate } = await kv.get([ FLUENTCI_KV_PREFIX, - "runs_by_date", - project, - dayjs(_.get(run, "date", data.date)).unix(), + "run_date", + data.id, ]); + if (runDate) { + await kv + .atomic() + .delete([FLUENTCI_KV_PREFIX, "runs_by_date", project, runDate]) + .delete([FLUENTCI_KV_PREFIX, "run_date", data.id]) + .commit(); + } + await kv .atomic() .set([FLUENTCI_KV_PREFIX, "runs", project, data.id], data) @@ -33,6 +40,10 @@ export async function save(project: string, data: Run) { ], data ) + .set( + [FLUENTCI_KV_PREFIX, "run_date", data.id], + dayjs(_.get(run, "date", data.date)).unix() + ) .set( [ FLUENTCI_KV_PREFIX,