Simple task repeated every N minutes - is there a solution for litestar? #4264
Unanswered
bunny-therapist
asked this question in
Q&A
Replies: 2 comments 2 replies
-
This seems to work?
It prints "Tick" every 5 seconds while the app is running. I am sure there are some problems with it. For example, I don't know how to make it async. |
Beta Was this translation helpful? Give feedback.
1 reply
-
Think about using APScheduler |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
We are using litestar apps in production, each being run by NGINX Unit and packaged inside a docker file, then run inside of a Kubernetes cluster.
As a new requirement, we now want some of the apps to be able to fetch configuration data from an external source (url) at regular intervals, for example, every 5 minutes, or 10 minutes, or 60 minutes or so (not every few seconds - it will never be that frequent), and of course also at start up, to actually have some config to work with.
I found this discussion: https://github.com/orgs/litestar-org/discussions/2311
It is 2 years old and I don't know if that is still the state of things. It referred me to this repo: https://github.com/cofin/litestar-saq
but the README there appears broken (and it is still on zero version). It also appears that I would need to have Redis (or Valkey? Maybe? Not sure.) running as well to get it to work (this is not documented, I just inferred this from the description and comparisons to RQ). So now I am not sure how to do this. Run a Redis instance inside each pod just to be able to have this job running? I ideally do not even want this to run in a separate process - I would have been fine with just running it async in the main thread, or spawn a thread - it just needs to fetch some data from an endpoint once in a while, validate that, then update the app config with it. All this workers and databases etc etc seems so incredibly heavyweight.
What is the recommended solution here? I am incredibly happy with litestar so far, but I feel like I am encountering the first real hurdle.
I see asyncio has some
call_later
method (https://docs.python.org/3/library/asyncio-eventloop.html#asyncio.lo) - can that work?Beta Was this translation helpful? Give feedback.
All reactions