Hi there,while trying to understand how to use the scheduler, i found this post:
In the Post, this code is writen:db.scheduler_task.insert(function_name='task1',task_name='task1',stop_time = now + timedelta(days=90000),repeats=0,period=10)gWhere do i put this code? in the model? I think this was partly answered in the post, but i dont understand it. can someone explain this to me?
Also, is there a way to let a scheduler run at a time writen in a db once and then rest until the next time occurs? or is a permanent run every few seconds checking for certain criteria the better solution?
And just to see if I understood this so far correctly:the scheduler function is basically a function I write into the model, offering everything a "normal" function offers, exectued at times i determine?
Alright, so far i am able to create the tables, but nothing runs.So far i have this:Model:database:dba = DAL(connection)dba.define_table('test_table',Field('test_table_id', 'integer'),Field('test_table_value'))scheduler:from gluon.scheduler import Schedulerscheduler = Scheduler(dba)controller:index:def start():import datetimedaytime_start = datetime.datetime(2017, 1, 1, 0, 0)a = 'a'dba.scheduler_task.insert(function_name='task_1',task_name='task_1',stop_time = daytime_start,repeats=0,period=10)
return dict(a=a)def index():text1 = 'test'return dict (text1=text1)module:test.py:def task_1():c= 0dba.test_table.insert(test_table_id = 1, test_table_value = 'a')db.commit()return dict(c=c)How do i get it startet, e.g. filling the test_table with those values every n seconds?Thank you very much for your help so far
scheduler.queue_task(
task_1,
pargs=[],
pvars={},
start_time=now, #datetime
stop_time = None, #datetime
timeout = 60, #seconds
prevent_drift=False,
period=60, #seconds
immediate=False,
repeats = 1
)I have read the book. But it doesn't state where to actually write the code snipes given. Both, the book and google is very fancy about explaining how to start a scheduler by the console. But i literally do not see how i can start the scheduler.
If i write this into the controller,scheduler.queue_task( task_1, pargs=[], pvars={}, start_time=now, #datetime stop_time = None, #datetime timeout = 60, #seconds prevent_drift=False, period=60, #seconds immediate=False, repeats = 1 )it atleast creates the tables and populates one of the tables with an set of records(scheduler_task) and does so whenever i call the function. But it only works as long as the function is in the same controller. if the function is in the modules, an error is returned. When i put this into the model, it creates the tabels but does not populate any of them.some possible reasons why it does not run i have made up are:-i'm queueing tasks but not creating a worker to work on them (but the book doesnt state anywhere to create a worker. I think therefore this cant be the solution)
-the function isn't defined proper and the worker does not know what to do.
if anyone wants to familiarize with the scheduler, I always recommend https://github.com/niphlod/w2p_scheduler_tests
from gluon.scheduler import Scheduler
def auto_insert(): try: db.UserLogs.insert(user_name='temp',user_email='a...@as.com',activity='checking scheduler') return 'inserted' except: return 'failed'
scheduler = Scheduler(db, dict(auto_insert=auto_insert))
[taship@taship web2py]$ python web2py.py -K taportaltestweb2py Web FrameworkCreated by Massimo Di Pierro, Copyright 2007-2016Version 2.9.11-stable+timestamp.2014.09.15.23.35.11Database drivers available: SQLite(sqlite3), MySQL(pymysql), PostgreSQL(pg8000), MSSQL(pyodbc), DB2(pyodbc), Teradata(pyodbc), Ingres(pyodbc), IMAP(imaplib)starting single-scheduler for "taportaltest"...0=unlimited -1=unlimited seconds Cron-like start_times between runs seconds update output every n sec: 0=never
scheduler_run.id scheduler_run.task_id scheduler_run.status scheduler_run.start_time scheduler_run.stop_time scheduler_run.run_output scheduler_run.run_result scheduler_run.traceback scheduler_run.worker_name 6 auto-insert COMPLETED 2016-05-28 16:18:47 2016-05-28 16:18:47 "inserted" None taship.iiit.a... 7 auto-insert COMPLETED 2016-05-28 16:19:06 2016-05-28 16:19:07 "inserted" None taship.iiit.a... 8 auto-insert COMPLETED 2016-05-28 16:19:22 2016-05-28 16:19:22 "inserted" None taship.iiit.a... 9 auto-insert COMPLETED 2016-05-28 16:19:38 2016-05-28 16:19:40 "inserted" None taship.iiit.a... 10 auto-insert COMPLETED 2016-05-28 16:19:55 2016-05-28 16:19:56 "inserted" None