Is there a way to start tg from a different Controller rather than default RootController?

21 views
Skip to first unread message

D R Dinesh Kumar

unread,
May 24, 2017, 7:29:25 PM5/24/17
to TurboGears
Hi.

We would like to manage ShutDown situation for our application where we would like to divert all calls to the app to default/shutdown.html page when 'ShutDown' is enabled in .ini file.

For Ex:
in development.ini file
------------------------------------
app.shutdown = True
app.shutdown_msg = 'system is in maintenance'

if this is setup, then start the tg from ShutDownController() instead of RootController()

where as in, my root.py has
'--------------------------------------------
class ShutDown(BaseController):
    expose(template="templates.shutdown")
    def default(self,*lst, **kw):
        msg = config.get('shutdown_msg','system is temporarity shutdown. Sorry for the inconvenience')
        return dict(msg = msg)

class RootController(BaseController):
    ...
    ...
 
This was handled during commands.py script in TG1 with Cherrypy. 

Is there any way to do the same in TG2? or is there any better way to handle this scenario?

With Regards,
Dinesh.

Alessandro Molina

unread,
May 25, 2017, 5:07:33 AM5/25/17
to TurboGears
If I correctly understood what you are trying to do, it's pretty much the same that tgext.evolve does while running "evolutions".
tgext.evolve is an extension to run upgrade scripts that need a downtime of the system. While the evolutions are running the system is put in "maintenance mode" and is recovered once the evolutions completed.


Application wrappers are a TG specific middleware that can be injected through the request execution pipeline to change its behaviour.

Inside an application wrapper you can for example change the path of the served page and send user somewhere else, that is for example what the Custom Error Pages application wrapper provided by TG itself does -> https://github.com/TurboGears/tg2/blob/development/tg/appwrappers/errorpage.py#L87-L90


--
You received this message because you are subscribed to the Google Groups "TurboGears" group.
To unsubscribe from this group and stop receiving emails from it, send an email to turbogears+unsubscribe@googlegroups.com.
To post to this group, send email to turbo...@googlegroups.com.
Visit this group at https://groups.google.com/group/turbogears.
For more options, visit https://groups.google.com/d/optout.

D R Dinesh Kumar

unread,
May 25, 2017, 6:32:01 PM5/25/17
to TurboGears
Thank you Alessandro for the pointer. 
Will try this out.

With Regards,
Dinesh.
Reply all
Reply to author
Forward
0 new messages