Skip to content

Commit

Permalink
Merge pull request #46 from fluentci-io/fix/duplicated-runs
Browse files Browse the repository at this point in the history
fix: resolve issue with duplicated run entries
  • Loading branch information
tsirysndr authored May 30, 2024
2 parents 01c50a7 + faff30c commit b818167
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 17 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
result
demo*
demo*
kview
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ fluentci studio
fluentci --help

Usage: fluentci [pipeline] [jobs...]
Version: 0.14.5
Version: 0.14.6

Description:

Expand Down
2 changes: 1 addition & 1 deletion src/consts.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand Down
10 changes: 5 additions & 5 deletions src/server/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
});

Expand Down Expand Up @@ -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,
Expand All @@ -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!,
Expand Down
37 changes: 28 additions & 9 deletions src/server/kv/runs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,21 @@ 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
);

const { value: runDate } = await kv.get<number>([
FLUENTCI_KV_PREFIX,
"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)
Expand All @@ -34,6 +40,19 @@ 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,
"runs_by_date",
project,
dayjs(_.get(run, "date", data.date)).unix(),
],
data
)
.commit();
}

Expand Down

0 comments on commit b818167

Please sign in to comment.