Not related, but looking for help
I'm currently running my app using celery and uvicorn - it's a fast api application. Given the amount of things i'm doing, the app leaves a significant memory leak after the processing, which can be fixed with a restart, right now, i'm using railway cron.
I wanted to see if there's a way to restart celery when there are no ongoing tasks, i'm looking at supervisor, memory leaks but if there's an easy way to trigger graceful restart, i would appreciate any help!
10 Replies
Project ID:
N/A
n/a
there's not going to be anything native to help you with this, you'd have to build something custom yourself to do what you want, the same way I built railway cron
have you tried calling the GC manually? or any other common memory leak tips and tricks?
A simple way to force a restart in your code is to simply quit your app and have Railway restart your app whenever it stops for any reason. That setting is in the service settings
oh yeah that's totally an option too!
though railway has had lots of reports of not properly detecting when the app exits so there's a chance that happens to your app and then your service never gets restarted
goal is to know if there are no ongoing tasks and then force a restart, i'm using celery and found that supervisord can help with this, but i'm not familar with it, so wanted to see if there was an option for graceful restart
right now, the restart (railway cron) kills the current task and becomes an issue
I'm sure there are multiple ways to do this, but at a high level you would need to poll celery and if there are no tasks for x amount of time, call a restart via the public api
or maybe run a celery task to poll itself for active tasks and have it restart itself
yes, i'm working on a monitor file and then if there's idle workers it'll restart
sounds like a great start
unfortunately I can't be of much help since I'm not a python dev and have never done anything with celery
no worries, appreciate your help anyway