I think the web2py scheduler is the most amazing thing ever added to the platform. It is truly a wonder in that it works so well and has such a clean design.
I was trying to improve it in the most minor way -- I wanted to create a decorator that causes a function to be submitted to the scheduler instead of being executed directly. That way I could easily switch from background to foreground processing by commenting out the decorator, or add new functions to the scheduler by adding the decorator. Here's what I came up with: def scheduled(name="Scheduled",timeout=60): def wrap(f): def new_f(*a): current.db.scheduler_task.insert( task_name=name, function_name=f.__name__, args='"%s"'%str(list(a)), timeout=timeout) return new_f return wrap In this decorator, I only passed two variables to the scheduler -- task_name and timeout. The heck of it is, I think the decorator is working except I'm running into a conceptual problem with the scheduler in general. Using it I can create a new scheduled task: @scheduled(name='import_times') def import_cl2times(fid): from ssobjects import SsMessage from ssimporter import SsImportTimes if fid: fname=current.db.fileobject(fid).get('filename') SsImportTimes.cl2read(fid) msg=SsMessage(subject="Meet results",message="File import of meet results %s is complete."%fname) msg.send() return This code lives in a module and is called by the scheduler. Or.... maybe isn't. I seem to be having module/controller/model difficulty at the moment. I have much of my functionality in modules, to permit the speed of compiled code in my rather large and growing website. I would like to call the decorator from either the context of the models, or from tasks already running in the background, in a module. Yes, I have background tasks which schedule other background tasks. Have I mentioned how much I love the scheduler??!? I can't seem to get the various imports right to have the scheduler actually be able to run a bit of code in a module. i had it working at one point when the scheduler and all of its background tasks were in the model file. But I couldn't schedule tasks from a module since the module can't see the model's context. But now that everything is in modules, the scheduler can't seem to find the code to run it. Any help is appreciated. -- --- 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/groups/opt_out.