Git Product home page Git Product logo

Comments (7)

mbi avatar mbi commented on May 18, 2024

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.

from django-rosetta.

bmihelac avatar bmihelac commented on May 18, 2024

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.

from django-rosetta.

olasfar avatar olasfar commented on May 18, 2024

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

from django-rosetta.

DylanYoung avatar DylanYoung commented on May 18, 2024

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?

from django-rosetta.

chitak avatar chitak commented on May 18, 2024

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>')

from django-rosetta.

DylanYoung avatar DylanYoung commented on May 18, 2024

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

from django-rosetta.

jepaulbadillos avatar jepaulbadillos commented on May 18, 2024

Any working workaround?

from django-rosetta.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.