R
Railway15mo ago
Yash

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
Percy
Percy15mo ago
Project ID: N/A
Yash
YashOP15mo ago
n/a
Brody
Brody15mo ago
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?
Adam
Adam15mo ago
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
Brody
Brody15mo ago
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
Yash
YashOP15mo ago
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
Brody
Brody15mo ago
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
Yash
YashOP15mo ago
yes, i'm working on a monitor file and then if there's idle workers it'll restart
Brody
Brody15mo ago
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
Yash
YashOP15mo ago
no worries, appreciate your help anyway
Want results from more Discord servers?
Add your server