Thank you Mike!

I had forgotten "asbool()".
It takes time locally to load my page but I finally allow specific route 
while having the maintenance mode activated.
handler(request) takes time. 

I consider that my questions are answered and that  my problem is  solved. 

Thank you very much everybody: you helped me a lot. It is great to have 
found this Google Group.
Have a nice day!

Le samedi 9 janvier 2021 à 22:29:50 UTC+1, Mike Orr a écrit :

> Don't forget the 'asbool()'. Without it the 'in_maintenance' text
> setting value may be interpreted wrong. E.g., '0' or ' ' or 'false'
> would evaluate to True.
>
> On Sat, Jan 9, 2021 at 11:30 AM Mike Orr <slugg...@gmail.com> wrote:
> >
> > The includeme function takes care of all the tween registration for
> > you, so you just have to include the module using the
> > "pyramid.includes" setting or such. You've got that working.
> >
> > Since you're enabling maintenance mode with a config setting, and
> > you'll have to restart the application to change it, you can hoist the
> > 'in_maintenance' setting check into the includeme function. E.g.,
> >
> > if registry.settings.get("in_maintenance", False):
> > tween = __name__ + ".maintenance_tween_factory"
> > config.add_tween(tween)
> >
> > That way the tween will be registered only if maintenance mode is
> > enabled. That will simplify your tween code slightly and is one
> > millisecond more efficient.
> >
> > As for your other problems of the maintenance screen never appearing,
> > or not appearing with the right URLs (I'm not sure which), I would add
> > some print or logging statements in the tween function to confirm it's
> > being called and see what its request.url, request,matchdict, and
> > request.path are. (I prefer request.path over request.url.) They may
> > be different from what you expect, and if so we'd need to figure out
> > why.
> >
> > I would also simplify the 'if not ... or not ...' expressions. While I
> > don't see anything in particular wrong with them, there may be a logic
> > error buried in the expressions somewhere, and separating them out and
> > printing the intermediate values may reveal what it is
> >
> > On Fri, Jan 8, 2021 at 9:06 AM C J <work.ced...@gmail.com> wrote:
> > >
> > > I try to understand why my "or not" have no effect:
> > >
> > > def maintenance_tween_factory(handler, registry):
> > > # Return a tween callable.
> > > # 'handler' is the next tween or the WSGI application.
> > > # Deployment settings are in 'registry.settings'.
> > > def maintenance_tween(request):
> > > #print(request)
> > > is_maintenance_mode = registry.settings.get("in_maintenance")
> > > if is_maintenance_mode == "True":
> > > print(request.url)
> > > print("maintenance" in request.url) # True but still affected by the 
> maintenance mode
> > > url = request.route_url('maintenance')
> > > if \
> > > not "/api/dbmigration" in request.url \
> > > or not "maintenance" in request.url:
> > > return HTTPServiceUnavailable(
> > > "Please note that we will be performing important server maintenance 
> in a few minutes, during which time the server will be unavailable. If you 
> are in the middle of something important, please save your work or hold off 
> on any critical actions until we are finished."
> > > )
> > > #return HTTPServiceUnavailable(location=url)
> > >
> > > # # Could limit it to certain request.path's.
> > > # if not ("/api/dbmigration" in request.url and is_maintenance_mode == 
> "True") \
> > > # or not ("maintenance" in request.url and is_maintenance_mode == 
> "True"):
> > > # # Return an error response, bypassing the application.
> > > # return HTTPServiceUnavailable(
> > > # "Please note that we will be performing important server maintenance 
> in a few minutes, during which time the server will be unavailable. If you 
> are in the middle of something important, please save your work or hold off 
> on any critical actions until we are finished."
> > > # )
> > > else:
> > > # Call next tween/application and return its response unchanged.
> > > return handler(request)
> > > else:
> > > # Call next tween/application and return its response unchanged.
> > > return handler(request)
> > > return maintenance_tween
> > >>>
> > >>>
> > > --
> > > You received this message because you are subscribed to the Google 
> Groups "pylons-discuss" group.
> > > To unsubscribe from this group and stop receiving emails from it, send 
> an email to pylons-discus...@googlegroups.com.
> > > To view this discussion on the web visit 
> https://groups.google.com/d/msgid/pylons-discuss/3ea70938-5f98-4a6b-97ba-25dea5edc50dn%40googlegroups.com
> .
> >
> >
> >
> > --
> > Mike Orr <slugg...@gmail.com>
>
>
>
> -- 
> Mike Orr <slugg...@gmail.com>
>

-- 
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to pylons-discuss+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/pylons-discuss/d29c25b7-c8bb-4baa-a017-ef7f15b9f53fn%40googlegroups.com.

Reply via email to