django-rosetta
django-rosetta copied to clipboard
Autoreload with gunicorn?
Is there any chance to reload translation with gunicorn? Something similar to ROSETTA_WSGI_AUTO_RELOAD and ROSETTA_UWSGI_AUTO_RELOAD.
Hi.
Sorry for the delay, I also fling Django with gunicorn, so this would definitely be useful for me, too.
I think the cleanest way to accomplish generic reloading would be to simply add a setting that gets executed as a shell command, this could be e.g. "sudo supervisorctl restart myapp_gunicorn" or "touch myapp.wsgi" when running under mod_wsgi.
Hi all,
one way to approach this is through signals.
Currently rosetta trigger post_save signal and one could listen to this signal to reload gunicorn: https://github.com/mbi/django-rosetta/blob/develop/rosetta/views.py#L149
Did not tried but I think this should work:
from django.dispatch import receiver
from rosetta.signals import post_save
@receiver(post_save)
def restart_server(sender, **kwargs):
import os
os.system("kill -HUP `cat /tmp/myproject.pid`")
I do like idea that command for reloading is read from settings as this would allow different settings for dev/prod environments.
Here is similar approach to trigger django dev server reloading:
from django.dispatch import receiver
from rosetta.signals import post_save
@receiver(post_save)
def restart_server(sender, **kwargs):
import os
os.system("sleep 1 && echo \"Rosetta reload\" && touch %s &" % __file__)
Note: running this process in background and sleeping for one second should give current rosetta view to redirect properly.
+1 Do you know guys when this will be fixed ? Is there any workaround ? Thx
I'm curious as I'm unfamiliar with the internals, but is the reload/restart necessary?
Would this snippet implemented as a post_save receiver (instead of middleware) accomplish the same?
Not sure what is the status for this, because I am using supervisor+gunicorn, so I modify slightly this snippet, and it works. I define this in my signals.py
@receiver(post_save)
def restart_server(sender, **kwargs):
os.system('supervisorctl restart <myproject>')
@chitak The problem with that is it will only work if your web application user has permission to use supervisorctl, which is not a particularly scalable or common setup, I think. If you want a more robust solution, try with the snippet I posted above.
Any working workaround?