Compare commits

..

3 Commits

Author SHA1 Message Date
291d2744af docs: update README
add folder info about middleware
2025-12-18 23:43:12 -05:00
e9864f42b1 feat: use luxon for TTL 2025-12-18 23:43:11 -05:00
0cdfbd5c56 chore: add debug logging to help understand why episode updates won't run 2025-12-18 23:43:11 -05:00

View File

@@ -276,11 +276,13 @@ 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);
}
@@ -290,13 +292,11 @@ 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);
}