Skip to content

Commit

Permalink
Delete expires kv rows
Browse files Browse the repository at this point in the history
  • Loading branch information
omfj committed Jul 18, 2024
1 parent efc36da commit 91cd0bd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
6 changes: 6 additions & 0 deletions apps/crons/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,9 @@ Unban users that have invalid strikes.
> Runs every day at 16:00.
Send an email to notify of new feedbacks.

## Delete expired kv entries

> Runs every day at 00:00.
Delete kv entries that have expired.
12 changes: 12 additions & 0 deletions apps/crons/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,16 @@ kroner.at("0 16 * * *", async (c) => {
await c.vars.email.send(to, subject, body);
});

kroner.at("0 0 1 1 *", async (c) => {
const keys = await c.vars.db.selectFrom("kv").selectAll().execute();

for (const key of keys) {
const expiration = key.ttl?.getTime();
if (expiration && expiration < Date.now()) {
await c.vars.db.deleteFrom("kv").where("key", "=", key.key).execute();
Logger.info(`Deleted kv entry: ${key.key}`);
}
}
});

export default kroner;

0 comments on commit 91cd0bd

Please sign in to comment.