Skip to content

Commit

Permalink
fix: resolve issue with duplicated runs entries
Browse files Browse the repository at this point in the history
  • Loading branch information
tsirysndr committed May 30, 2024
1 parent 01c50a7 commit 16dd3ae
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
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
26 changes: 17 additions & 9 deletions src/server/kv/runs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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();
}

Expand Down

0 comments on commit 16dd3ae

Please sign in to comment.