Compare commits
3 Commits
291d2744af
...
28bb39474f
| Author | SHA1 | Date | |
|---|---|---|---|
| 28bb39474f | |||
| 7cf0c4c1c7 | |||
| 45f6f678b6 |
@@ -276,13 +276,11 @@ export class AnilistDurableObject extends DurableObject {
|
|||||||
|
|
||||||
const result = await fetcher();
|
const result = await fetcher();
|
||||||
await this.state.storage.put(key, result);
|
await this.state.storage.put(key, result);
|
||||||
console.debug(`Retrieved alarms from cache:`, Object.entries(alarms));
|
|
||||||
|
|
||||||
const calculatedTtl = typeof ttl === "function" ? ttl(result) : ttl;
|
const calculatedTtl = typeof ttl === "function" ? ttl(result) : ttl;
|
||||||
if (calculatedTtl) {
|
if (calculatedTtl) {
|
||||||
const alarmTime = calculatedTtl.toMillis();
|
const alarmTime = calculatedTtl.toMillis();
|
||||||
await this.state.storage.setAlarm(alarmTime);
|
await this.state.storage.setAlarm(alarmTime);
|
||||||
console.debug(`Deleting storage key ${storageKey} & alarm ${key}`);
|
|
||||||
await this.state.storage.put(`alarm:${key}`, alarmTime);
|
await this.state.storage.put(`alarm:${key}`, alarmTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -292,11 +290,13 @@ export class AnilistDurableObject extends DurableObject {
|
|||||||
async alarm() {
|
async alarm() {
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
const alarms = await this.state.storage.list({ prefix: "alarm:" });
|
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)) {
|
for (const [key, ttl] of Object.entries(alarms)) {
|
||||||
if (now >= ttl) {
|
if (now >= ttl) {
|
||||||
// The key in alarms is `alarm:${storageKey}`
|
// The key in alarms is `alarm:${storageKey}`
|
||||||
// We want to delete the storageKey
|
// We want to delete the storageKey
|
||||||
const storageKey = key.replace("alarm:", "");
|
const storageKey = key.replace("alarm:", "");
|
||||||
|
console.debug(`Deleting storage key ${storageKey} & alarm ${key}`);
|
||||||
await this.state.storage.delete(storageKey);
|
await this.state.storage.delete(storageKey);
|
||||||
await this.state.storage.delete(key);
|
await this.state.storage.delete(key);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user