Skip to content

Commit 4beae5c

Browse files
committed
fix: keeper bot hardening, flushing the logs, sending several heartbeats
1 parent b2afc01 commit 4beae5c

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

contracts/scripts/keeperBot.ts

+19-6
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,15 @@ const filterAsync = async <T>(
156156

157157
const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
158158

159+
const sendHeartbeat = async () => {
160+
if (HEARTBEAT_URL) {
161+
logger.debug("Sending heartbeat");
162+
fetch(HEARTBEAT_URL);
163+
} else {
164+
logger.debug("Heartbeat not set up, skipping");
165+
}
166+
};
167+
159168
async function main() {
160169
const { core, sortition, disputeKitClassic } = await getContracts();
161170

@@ -193,6 +202,8 @@ async function main() {
193202
return (await sortition.phase()) === 2;
194203
};
195204

205+
await sendHeartbeat();
206+
196207
// get all the non-final disputes
197208
const nonFinalDisputesRequest = `{
198209
disputes(where: {period_not: execution}) {
@@ -270,6 +281,8 @@ async function main() {
270281
}
271282
}
272283

284+
await sendHeartbeat();
285+
273286
for (dispute of disputes) {
274287
await passPeriod(dispute);
275288

@@ -315,17 +328,17 @@ async function main() {
315328
}
316329
}
317330

318-
if (HEARTBEAT_URL) {
319-
logger.debug("Sending heartbeat");
320-
fetch(HEARTBEAT_URL);
321-
} else {
322-
logger.debug("Heartbeat not set up, skipping");
323-
}
331+
await sendHeartbeat();
332+
333+
await delay(2000); // Some log messages may be lost otherwise
324334
}
325335

326336
main()
327337
.then(() => process.exit(0))
328338
.catch((error) => {
329339
console.error(error);
330340
process.exit(1);
341+
})
342+
.finally(() => {
343+
logger.flush();
331344
});

0 commit comments

Comments
 (0)