scheduler

42 views
Skip to first unread message

Frank

unread,
Apr 22, 2014, 1:32:03 PM4/22/14
to web...@googlegroups.com
Hi,

/newbie here/

I’ve up and running a very very simple task scheduler but I think it’s not well designed :/

under models/scheduler.py I have:

"
from gluon.scheduler import Scheduler

def task_add(name, target):
    sum = 'hello ' + name + ' ' + target + '\n'
    with open('/tmp/tasks', 'w') as f:
        f.write(sum)

scheduler = Scheduler(db, dict(task_add=task_add))

and in controller:

def new():

    form = SQLFORM(db.scan)
 
    name = “”
    target = “"

    if form.process().accepts(request.vars, session):

        name = form.vars.name
        target = form.vars.target

        response.flash = ‘Great scan'

    elif form.errors:
        response.flash = 'Error, try again'

    scheduler.queue_task('task_add’,
pargs=[],
        pvars={'name': name, 'target': target},
        start_time=request.now,     #datetime
        stop_time = None,           #datetime
        timeout = 60,               #seconds
        prevent_drift=False,
        period=60,                  #seconds
        immediate=False,
        repeats = 1)

    return dict(scans=scans, form=form)

This snippet is working but I think this “scheduler.queue_task(…)” should be processed inside “if form.process().accepts()”. But if I change the scheduler snipper into that code section, the task wont run and I don’t know why.

two: questions
1) what I am  doing wrong?
1.1) Maybe I should db.commit when the task is over. Should I code this under scheduler.py? 
2) where can I learn more about debugging?

Many many thanks in advance :)

Cheers,
-- 
Frank

Niphlod

unread,
Apr 23, 2014, 3:59:47 PM4/23/14
to web...@googlegroups.com
you're doing "all" wrong. Stop copy/pasting for a sec and take a look to docs.....it'll save you from multiple headaches.

in this case, you're "doing wrong" form processing.

It's either

form = SQLFORM(...)
if form.accepts(request.vars, session):
   
....things to do when form is valid
elif form.errors:
   
....things to do when form has errors
else:
   
....things to do when page is loaded the first time
return dict(form=form)



or (newer)

form = SQLFORM(...)
if form.process().accepted:
   
....things to do when form is valid
elif form.errors:
   
....things to do when form has errors
else:
   
....things to do when page is loaded the first time
return dict(form=form)

Frank

unread,
Apr 23, 2014, 4:53:01 PM4/23/14
to web...@googlegroups.com, Niphlod
Hi Niphold,

many thanks for your reply and valuable tips.

On 23 Apr 2014 at 20:59:52, Niphlod (nip...@gmail.com) wrote:

you're doing "all" wrong. Stop copy/pasting for a sec and take a look to docs.....it'll save you from multiple headaches.

Despite my error, isn’t it normal doing some copy-past while giving  first steps?



in this case, you're "doing wrong" form processing.

It's either

form = SQLFORM(...)
if form.accepts(request.vars, session):
   
 ....things to do when form is valid
elif form.errors:
   
 ....things to do when form has errors
else:
   
 ....things to do when page is loaded the first time
return dict(form=form)



or (newer)

form = SQLFORM(...)
if form.process().accepted:
   
 ....things to do when form is valid
elif form.errors:
   
 ....things to do when form has errors
else:
   
 ....things to do when page is loaded the first time
return dict(form=form)



I’ve changed the code to this last newer form and it is working fine.
Yes It makes sense but I think what confuses me most is the ‘so many ways to do it’.

Meanwhile, looking here http://web2py.com/books/default/chapter/29/07/forms-and-validators I can’t figure where is the newer or ‘older’ version.

regards,
Frank

--
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+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Niphlod

unread,
Apr 24, 2014, 3:42:21 AM4/24/14
to web...@googlegroups.com, Niphlod


On Wednesday, April 23, 2014 10:53:01 PM UTC+2, ureal frank wrote:
Hi Niphold,

many thanks for your reply and valuable tips.

On 23 Apr 2014 at 20:59:52, Niphlod (nip...@gmail.com) wrote:

you're doing "all" wrong. Stop copy/pasting for a sec and take a look to docs.....it'll save you from multiple headaches.

Despite my error, isn’t it normal doing some copy-past while giving  first steps?


For some peoples, apparently : I'm just saying that you'll save headaches NOT copy/pasting :P
 

I’ve changed the code to this last newer form and it is working fine.
Yes It makes sense but I think what confuses me most is the ‘so many ways to do it’.

Meanwhile, looking here http://web2py.com/books/default/chapter/29/07/forms-and-validators I can’t figure where is the newer or ‘older’ version.

Frank

unread,
Apr 24, 2014, 6:35:54 AM4/24/14
to web...@googlegroups.com, Niphlod, Niphlod
On 24 Apr 2014 at 08:42:27, Niphlod (nip...@gmail.com) wrote:


On Wednesday, April 23, 2014 10:53:01 PM UTC+2, ureal frank wrote:
Hi Niphold,

many thanks for your reply and valuable tips.

On 23 Apr 2014 at 20:59:52, Niphlod (nip...@gmail.com) wrote:

you're doing "all" wrong. Stop copy/pasting for a sec and take a look to docs.....it'll save you from multiple headaches.

Despite my error, isn’t it normal doing some copy-past while giving  first steps?


For some peoples, apparently : I'm just saying that you'll save headaches NOT copy/pasting :P

web2py stack is huge. the documentation is also huge and detailed.
this is great but for newbies this is massive :)
hey this is not an escuse, I have too many things to learn and I am loving it.


 

I’ve changed the code to this last newer form and it is working fine.
Yes It makes sense but I think what confuses me most is the ‘so many ways to do it’.

Meanwhile, looking here http://web2py.com/books/default/chapter/29/07/forms-and-validators I can’t figure where is the newer or ‘older’ version.

It's the first section on FORM and SQLFORM :D

Oh I see… I was understanding it wrong…
I though that in the handbook I would read a bold ‘deprecated’ vs ‘new way of doing things’.

Once again many thanks for your help and time :) 

Regards,
Frank

Reply all
Reply to author
Forward
0 new messages