Web2py Scheduler, db query is not executing.

21 views
Skip to first unread message

Andrew

unread,
Oct 5, 2021, 9:49:44 AM10/5/21
to web2py-users
Hello, I am trying to run a database query using the web2py scheduler, but for some reason I can't get the query to commit. I've tested the function in a controller to see that it works, and I'm pretty sure the scheduler is running correctly because I have a scheduler_worker with the status of ACTIVE in my backend.

this is my scheduler.py in models:

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

def delete_after_hours():
    current_start = now
    start = current_start.replace(tzinfo=utc)
    rows = db(db.public_uploads.id > 0).select()
    for row in rows:
        end_time = row.end_time
        end = end_time.replace(tzinfo=utc)
        if start >= end:
            row.delete_record()

scheduler.queue_task(delete_after_hours)


Thanks in advance for any advice.

*cheers

Jim S

unread,
Oct 5, 2021, 2:37:11 PM10/5/21
to web2py-users
Have you tried adding a db.commit() to your delete_after_hours() function?

-Jim



Reply all
Reply to author
Forward
0 new messages