Skip to content

Commit

Permalink
feat: add better logging from crons
Browse files Browse the repository at this point in the history
  • Loading branch information
peterferguson committed Apr 4, 2024
1 parent bf4f54d commit 3558859
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/actions/sync-pending-members.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export async function syncPendingMembers() {
const address = chainAwareAddress.split(":").at(-1);
if (id && groupId && address) {
try {
console.log(`adding ${address} to group ${groupId}`);
await bot.addMembers(groupId, [address]);
await db
.delete(schema.pendingGroupMembers)
Expand Down
19 changes: 13 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import { getOwnersSafes } from "./actions/get-owners-safes";
import { getGroupsByWalletAddresses } from "./actions/get-group-by-wallet-address";
import { addMembers } from "./actions/add-members";
import { removeMembers } from "./actions/remove-members";
import cron from "@elysiajs/cron";
import { cron, Patterns } from "@elysiajs/cron";
import { db } from "./db";
import { sql } from "drizzle-orm";

/**
* This service is responsible for keeping xmtp group chat members in sync with the members of a safe.
Expand All @@ -36,20 +38,25 @@ export default new Elysia()
.use(
cron({
name: "heartbeat",
pattern: "*/10 * * * * *", // every 10 seconds
pattern: Patterns.EVERY_10_SECONDS,
run() {
console.log("Heartbeat");
console.log(
`app.db size -> ${
db.get<[number]>(
sql`SELECT page_count * page_size as size FROM pragma_page_count(), pragma_page_size();`,
)[0] / 1024
} KB`,
);
},
}),
)
.use(
cron({
name: "sync-pending-members",
pattern: "* */5 * * * *", // every 5 minutes
pattern: Patterns.EVERY_5_MINUTES,
async run() {
console.log("try sync pending members");
const pendingMembers = await syncPendingMembers();
return JSON.stringify(pendingMembers, null, 4);
await syncPendingMembers().catch((e) => console.error(e));
},
}),
)
Expand Down

0 comments on commit 3558859

Please sign in to comment.