django-rosetta icon indicating copy to clipboard operation
django-rosetta copied to clipboard

Autoreload with gunicorn?

Open elioscordo opened this issue 12 years ago • 7 comments

Is there any chance to reload translation with gunicorn? Something similar to ROSETTA_WSGI_AUTO_RELOAD and ROSETTA_UWSGI_AUTO_RELOAD.

elioscordo avatar Sep 14 '12 17:09 elioscordo

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.

mbi avatar Nov 06 '12 17:11 mbi

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.

bmihelac avatar Nov 07 '12 11:11 bmihelac

+1 Do you know guys when this will be fixed ? Is there any workaround ? Thx

olasfar avatar Jan 29 '17 22:01 olasfar

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?

DylanYoung avatar Aug 04 '17 17:08 DylanYoung

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 avatar Jan 08 '19 15:01 chitak

@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.

DylanYoung avatar Jan 08 '19 20:01 DylanYoung

Any working workaround?

jepaulbadillos avatar Sep 20 '23 08:09 jepaulbadillos