i do await myStoreKV.put(myKey, mydata)
but in another route, when i get it, it’s null
after a while like 10,20 seconds, the data is there as expected.
how can i make workers kv synchronous?
i do await myStoreKV.put(myKey, mydata)
but in another route, when i get it, it’s null
after a while like 10,20 seconds, the data is there as expected.
how can i make workers kv synchronous?
@tuananh , your questions is quite general. Can you provide more details, and what are you trying exactly to achieve?
What exactly you mean by synchronous
, if you give a full example of your project and code, maybe someone familiar with the workers scripting can help you more, if we know the concept
Please follow the DOCS here:
From the docs @StefanoWP linked to:
KV achieves this performance by being eventually-consistent. New key-value pairs are immediately available everywhere, but value changes may take up to 60 seconds to propagate.
Emphasis mine. I’ve heard this before, probably from Kenton – KV updates aren’t instantaneous across the network.
this seems to be my problem. I have a test suite and it keeps failing but inconsistently. sometimes changes are fast and sometimes it’s slow. I missed that bit in the docs.
Thank you.
Testing workers is a bit difficult in combination with KV (and without it).
There’s this method which can simulate KV’s (see cloudworker docs):
However, I found that local tests aren’t as reliable as running the tests on a deployed (live) worker, so I created a second worker script that has access to the main scripts KV’s and write tests in that script.
I’m using simple fetch and vanilla JS for the tests (I found no test-framework that’s small enough to fit inside a worker and don’t require node) and if I cannot read the KV value directly, then I add an “expect” loop that waits for the expected value.
Right, so now you’re wondering - what about the worker time-limit? You’re right, you’re not able to run long-running tests in a worker script - so we add a front-end to initiate a test or multiple (or you can just trigger a route manually).
And then… (This is ending, I promise…) what about logging, how do I know why the test fails since I have no console? You can use this: https://console.watch/ or roll your own logging, or you can try logflare: https://logflare.app