Compare commits

..

3 Commits

Author SHA1 Message Date
28bb39474f docs: update README
add folder info about middleware
2025-12-18 23:47:28 -05:00
7cf0c4c1c7 feat: use luxon for TTL 2025-12-18 23:47:28 -05:00
45f6f678b6 chore: add debug logging to help understand why episode updates won't run 2025-12-18 23:47:27 -05:00

View File

@@ -276,13 +276,11 @@ export class AnilistDurableObject extends DurableObject {
const result = await fetcher();
await this.state.storage.put(key, result);
console.debug(`Retrieved alarms from cache:`, Object.entries(alarms));
const calculatedTtl = typeof ttl === "function" ? ttl(result) : ttl;
if (calculatedTtl) {
const alarmTime = calculatedTtl.toMillis();
await this.state.storage.setAlarm(alarmTime);
console.debug(`Deleting storage key ${storageKey} & alarm ${key}`);
await this.state.storage.put(`alarm:${key}`, alarmTime);
}
@@ -292,11 +290,13 @@ export class AnilistDurableObject extends DurableObject {
async alarm() {
const now = Date.now();
const alarms = await this.state.storage.list({ prefix: "alarm:" });
console.debug(`Retrieved alarms from cache:`, Object.entries(alarms));
for (const [key, ttl] of Object.entries(alarms)) {
if (now >= ttl) {
// The key in alarms is `alarm:${storageKey}`
// We want to delete the storageKey
const storageKey = key.replace("alarm:", "");
console.debug(`Deleting storage key ${storageKey} & alarm ${key}`);
await this.state.storage.delete(storageKey);
await this.state.storage.delete(key);
}