Hi.
There must be something wrong with what you expect.
The scheduler is an ASYNC process, meaning that - usually - trying to fetch 
the result in the same request that queued it is a wrong idea in so many 
ways that should be obvious.
That being said, this works without any issues.

models/scheduler.py
def add(a,b):
    return a + b

from gluon.scheduler import Scheduler
mysched = Scheduler(db)

controllers/default.py

def index():
    thetask = mysched.queue_task('add', pargs=[3,4])
    db.commit() #otherwise the scheduler process can't see it
    result = None
    task_id = None
    while 1:
        intermediate = mysched.task_status(thetask.uuid, output=True)
        if intermediate.result:
            result = intermediate.result
            task_id = thetask.uuid
            break
        time.sleep(1)
    return dict(res=result, task_id=task_id)

On Wednesday, May 28, 2014 5:55:20 PM UTC+2, Cory wrote:
>
> Hi,
> I am having trouble getting the run_result after  web2py has finished a 
> task using web2py's scheduler. 
> The code below is what I am using. The trouble I am having is grabbing the 
> result once the result is 
> ready. Do any of you know how to get the run_result from a task once the 
> task has finished? right now
> when I try to get the run_result I get a "None" value because I try to get 
> the result before it is ready.
> The task can take a couple of seconds to finish. I have tried many 
> different ways to get the result once
> it is ready. For instance, creating a while loop that checks to see if the 
> task status has changed to 
> "completed" then grab the result, but that does not work. Any ideas? I 
> have been stuck on this far too long.
>
>         task2 = sched.queue_task('upsQuote', pargs = [session.Weight, 
> session.OrigZip, session.DestZip], timeout = 5, start_time = request.now)   
>  #add the task 
>         task_status2  = sched.task_status(task2.uuid, output=True)    # 
> get the task status 
>         result2 = task_status2.scheduler_run.run_result                   
>    # get the result from the finished task 
>
>
>

-- 
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to