> > I'm going to have perhaps a hundred little functions that the scheduler > inserts into the queue. Now, if I define my little functions in the same > Model page as the scheduler, everything works as expected. Each of my > functions is like a stub -- it generally provides a call point for the > scheduler but then accesses code in a module somewhere. Although each > function is kept as small as possible, I'm still loading a large number of > little functions with every web page access, activity I would like to avoid. >
There is no need to define the task functions in model files -- they can be completely defined in modules and simply imported into a model file. You do not need "stub" functions. > There is a dictionary I can pass to the scheduler which names each of the > functions to be used as entries, but then I have to create a dictionary > with a large number of entries, each time a web page is called. Again, > activity I'd rather avoid in the 99.9999% of web page accesses that don't > need or use the scheduler. > First, you do not need the dictionary. If you import or define functions in a model, they will then be in the web2py environment, and you can refer to the functions directly in scheduler.queue_task(). Second, if you do want a dictionary, you can define the dictionary itself in a module and simply import it in the model where you define the scheduler. > Plus I'm not sure I can create the dictionary if its functions are > scattered across controllers. > You cannot define your scheduler functions in controllers -- the scheduler does not execute controllers. > What is this dictionary for, and how can I avoid needing it at all? There > are only a few comments in the book regarding this topic. Mostly a warning > that the "workers must be restarted" if the dictionary changes. > The dictionary just allows you to map labels to functions (or other callable objects). If the functions themselves exist in the web2py environment where the scheduler is defined (i.e., by being defined or imported in a model file prior to the scheduler instantiation), then you can refer to the functions directly when queuing tasks. > (Has anyone noticed that stopping or restarting the workers is never > described? I presume this is a console process which makes it outsides the > bounds of what I'm looking for.) > Yes, web2py itself does not restart the scheduler. The scheduler runs separate operating system processes -- you start, stop, restart at the command line. > No matter what I try, unless the function is defined in the same model > page as the scheduler, all I get from the scheduler is "NameError: name > 'xxxxx' not found in scheduler's environment" even though I specifically > test to make sure it is visible when invoking web2py -M -S > app/controller/xxxxx > Again, note that the scheduler does not have access to functions in controllers. Anthony -- 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.