Thanks for the answer. I'm using web2py version 2.10.3, so in the model I did this:
_cmd_options = request.global_settings.cmd_options if not (_cmd_options and _cmd_options.scheduler): # this code is executed when the request is NOT done through scheduler Thank you both Anthony and Niphlod for your time. El miércoles, 13 de enero de 2016, 12:32:34 (UTC-3), Anthony escribió: > > There is a request object, but it doesn't have all the same attributes > during a scheduler run as it does during an HTTP request. Anyway, you can > determine whether the current execution is happening via the scheduler by > checking request.is_scheduler. Similarly, you can determine if in a shell > with request.is_shell. Note, these two attributes have only been working > properly since the latest release. In earlier versions, you would have to > check request.env.cmd_options.scheduler and request.env.cmd_options.shell. > > Anthony > > On Wednesday, January 13, 2016 at 9:44:13 AM UTC-5, Lisandro wrote: >> >> Thanks for the answer. >> I've found that one of my models does a conditional check on request >> object. >> However, when the function is called from the scheduler, there is no HTTP >> request, so there is no request object. >> >> Is there a way to check if request object exists from inside the model? >> >> I've tried this: >> if 'request' in globals(): >> #do stuff here >> >> and this >> try: >> request = request >> except: >> request = None >> if request: >> #do stuff here (I know, this is really bad thing to do) >> >> Thanks in advance >> >> >> >> >> >> El martes, 12 de enero de 2016, 16:59:26 (UTC-3), Niphlod escribió: >>> >>> it seems an error in the model definition, as line 166 in gluon.shell is >>> where an exception is raised when executing model files BEFORE calling the >>> controller. >>> As I repeatedly said, scheduler is just calling shell at regular >>> intervals on steroids. If it works on the shell, it'll work on the >>> scheduler too. >>> >>> so, 1st step. What if you execute the function in the shell directly ? >>> >>> web2py.py -M -S appname/controller_name/function_name >>> >>> The only thing that can sometimes get you in the corner is conditional >>> models ... If you're using them, be sure when you are queuing the task, >>> that you do from the same controller which triggers the same conditional >>> models where the function is defined. >>> Remember that the scheduler executes the same environment where the >>> queuing happened if you don't pass an explicit application_name parameter >>> (by default is current.request.application/current.request.controller) >>> which executes models/* and models/controller_name but not >>> models/other_controller_name >>> >>> On Tuesday, January 12, 2016 at 5:50:52 PM UTC+1, Lisandro wrote: >>>> >>>> I'm seeing this traceback error when I try to run a function defined in >>>> a model: >>>> >>>> Traceback (most recent call last): File >>>> "/var/www/medios/gluon/scheduler.py", line 295, in executor _env = env( >>>> a=a, c=c, import_models=True) File "/var/www/medios/gluon/shell.py", >>>> line 166, in env sys.exit(1) SystemExit: 1 >>>> >>>> However, if I call the function from within a controller/function, the >>>> function executes ok. >>>> As I don't see an error pointing to my app's code, I thought I could >>>> ask here. What am I missing? >>>> >>> -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.