Add flag to persist builds
Some checks failed
Some checks failed
This commit is contained in:
18
src/DB.ts
18
src/DB.ts
@@ -30,6 +30,7 @@ interface Build {
|
||||
pid?: number;
|
||||
sqid?: string;
|
||||
uuid: string;
|
||||
persist: boolean;
|
||||
}
|
||||
|
||||
interface User {
|
||||
@@ -128,6 +129,10 @@ class DB extends Store {
|
||||
uuid: {
|
||||
type: DataTypes.STRING,
|
||||
unique: true
|
||||
},
|
||||
persist: {
|
||||
type: DataTypes.BOOLEAN,
|
||||
defaultValue: false
|
||||
}
|
||||
});
|
||||
|
||||
@@ -262,6 +267,16 @@ class DB extends Store {
|
||||
});
|
||||
}
|
||||
|
||||
public async persist(id: number, persist: boolean = true): Promise<void> {
|
||||
await this.build.update({
|
||||
persist
|
||||
}, {
|
||||
where: {
|
||||
id
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public async appendLog(buildId: number, type: LogType, chunk: string): Promise<void> {
|
||||
await this.logChunk.create({
|
||||
buildId,
|
||||
@@ -366,7 +381,8 @@ class DB extends Store {
|
||||
public async cleanup(): Promise<void> {
|
||||
await this.build.destroy({
|
||||
where: {
|
||||
startTime: { [Op.lt]: new Date(Date.now() - MONTH * 6) }
|
||||
startTime: { [Op.lt]: new Date(Date.now() - MONTH * 6) },
|
||||
persist: { [Op.eq]: false }
|
||||
},
|
||||
force: true
|
||||
});
|
||||
|
||||
11
src/Web.ts
11
src/Web.ts
@@ -297,6 +297,17 @@ class Web {
|
||||
res.redirect(`/build/${req.params.id}/`);
|
||||
});
|
||||
|
||||
app.post('/build/:id/persist', async (req, res) => {
|
||||
const build = await this.db.getBuild(sqids.decode(req.params.id)?.[0]);
|
||||
const persist = !! req?.body?.persist;
|
||||
if (!build) {
|
||||
res.sendStatus(404);
|
||||
return;
|
||||
}
|
||||
await this.db.persist(build.id, persist);
|
||||
res.sendStatus(200);
|
||||
})
|
||||
|
||||
this._webserver = this.app.listen(this.port, () => console.log(`archery is running on port ${this.port}`));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user