Closed tamo closed 5 months ago
I'll check further whether this is legit
~Deno's unload doesn't seem to allow me to Kv.set.~ Deno deploy doesn't allow me to do anything before killing the instance. So events of Kv's closing / unloading would be great. I would like to Kv.set when (or just before) an instance of Deno deploy exits.
Signals can't save me either
const kv = await Deno.openKv();
const setandexit = (signame: string) => (() => {
console.log(signame);
kv.set(["last shutdown"], new Date().toISOString())
.then(() => console.log("set"));
setTimeout(() => Deno.exit(), 1000);
});
for (const signame of ["SIGHUP", "SIGINT", "SIGTERM", "SIGPIPE"] as Deno.Signal[])
Deno.addSignalListener(signame, setandexit(signame));
Deno.serve(async () => new Response(
String((await kv.get(["last shutdown"])).value)
));
@tamo What happens if you await
the kv.set
call?
@tamo What happens if you
await
thekv.set
call?
Looks the same. Kv has no data after restarting the instance. https://dash.deno.com/playground/low-ape-11
Ah, sorry. Signal handlers are not supported in Deploy (They are just no-op functions in Deploy). unload
and beforeunload
events are also not supported.
I'm curious what you would want to accomplish by saving data at instance termination.
Thank you for the clarification! Fair enough that they are not supported. I'm closing this issue.
What I wanted to do was, in short, to keep some data over rebooting, while avoiding Kv.set/get as much as possible.
(Date.now() - (the time it previously fetched the page) > (constant value))
: if true, it will fetch the page again and refresh the cache(Date.now() - (the time it previously *updated the Kv*) > (constant value)
https://github.com/tamo/shm-rss/blob/801c5e0ff3d1d602415b7a396b751d9f475bd9f7/shm.ts#L310-L314
🔍
Type of feedback
Feature request
Description
Deno KV is great. It helps me code as soon as an idea comes up. Today I thought it would be useful to save some values on unload (because Deno Deploy shuts down often) and load the values on next startup. But ~KV doesn't seem to be available on unload or beforeunload.~ unload events are not triggered when a Deno deploy instance is destroyed.
Steps to reproduce (if applicable)
Something like
Expected behavior (if applicable)
I'd like to get/set KV just before the deploy instance shuts down.
Possible solution (if applicable)
Maybe another event?
Additional context
In Deno Deploy context.