feat: add clean zombie builds scripts

This commit is contained in:
Javi Marti
2025-02-06 01:19:16 +01:00
parent 164155062a
commit 88a76d2ccf
3 changed files with 30 additions and 2 deletions

View File

@@ -6,6 +6,7 @@ COPY ./package.json /usr/local/app/
COPY ./package-lock.json /usr/local/app/
COPY ./src /usr/local/app/src
COPY ./prisma /usr/local/app/prisma
COPY ./scripts /usr/local/app/scripts
RUN npm install
RUN npm run build
@@ -16,6 +17,7 @@ WORKDIR /usr/local/app
COPY --from=build /usr/local/app/node_modules /usr/local/app/node_modules
COPY --from=build /usr/local/app/dist /usr/local/app/dist
COPY --from=build /usr/local/app/prisma /usr/local/app/prisma
COPY --from=build /usr/local/app/scripts /usr/local/app/scripts
RUN apt-get update && apt-get install -y git
@@ -28,4 +30,4 @@ RUN npx prisma generate
EXPOSE 8080
CMD npx prisma migrate deploy && node dist/index.mjs
CMD npx prisma migrate deploy && npm run zombie && node dist/index.mjs

View File

@@ -31,7 +31,8 @@
},
"scripts": {
"start": "tsx watch src/index.ts",
"build": "pkgroll ."
"build": "pkgroll .",
"zombie": "tsx scripts/zombie.ts"
},
"author": "",
"license": "ISC"

25
scripts/zombie.ts Normal file
View File

@@ -0,0 +1,25 @@
// This script cleans any zombie builds that are left in BUILDING status
import { PrismaClient } from "@prisma/client";
const prisma = new PrismaClient();
const clearZombieBuilds = async () => {
const builds = await prisma.build.findMany({ where: { status: "BUILDING" } });
await prisma.$transaction(
builds.map((build) =>
prisma.build.update({
where: { id: build.id },
data: { status: "FAILED", finishedAt: build.updatedAt },
})
)
);
return builds.length;
};
clearZombieBuilds().then((builds) => {
console.log(`Sucessfully fixed ${builds} builds`);
process.exit(0);
});