Improve event timeout with heartbeat_at
This commit is contained in:
@@ -89,9 +89,12 @@ export class EventsService {
|
||||
.execute();
|
||||
}
|
||||
|
||||
async setState(id: string, state: JsonValue) {
|
||||
async setState(id: string, state: JsonValue, shouldHeartbeat: boolean = true) {
|
||||
await db.updateTable("events")
|
||||
.set({ state })
|
||||
.set((eb) => ({
|
||||
state,
|
||||
heartbeat_at: shouldHeartbeat ? new Date() : eb.ref("heartbeat_at")
|
||||
}))
|
||||
.where("id", "=", id)
|
||||
.execute();
|
||||
}
|
||||
@@ -125,6 +128,7 @@ export class EventsService {
|
||||
async retry(id: string): Promise<boolean> {
|
||||
const result = await db.updateTable("events")
|
||||
.set({
|
||||
heartbeat_at: null,
|
||||
started_at: null,
|
||||
ended_at: null,
|
||||
has_failed: false,
|
||||
@@ -147,7 +151,7 @@ export class EventsService {
|
||||
}))
|
||||
.where("started_at", "is not", null)
|
||||
.where("ended_at", "is", null)
|
||||
.where("started_at", "<", new Date(Date.now() - EventsService.CONCURRENCY_TIMEOUT_MS))
|
||||
.where("heartbeat_at", "<", new Date(Date.now() - EventsService.CONCURRENCY_TIMEOUT_MS))
|
||||
.$if(opt.filter?.type !== undefined, (qb) => qb.where("type", "=", opt.filter!.type!))
|
||||
.$if(opt.filter?.group !== undefined, (qb) => qb.where("group", "=", opt.filter!.group!))
|
||||
.returning(["id"])
|
||||
|
||||
Reference in New Issue
Block a user