Hello
In my web2py app i am using scheduler. So far I have one task scheduled which runs a subprocess when called from controler (an external exe file/application)
Now i want to add another task which will do some background work
My code in scheduler.py till now was
def runWoshiEngine(scriptId, path):
# import os, sys
# import time
import subprocess
print "runWoshiEngine in progress......"
p = subprocess.Popen(['woshi_engine.exe', scriptId], shell=True, stdout = subprocess.PIPE, cwd=path)
return dict(status = 1)
from gluon.scheduler import Scheduler
scheduler = Scheduler(db, heartbeat = 1)
so this way the scheduler started on client's request
after starting my app I run my scheduler with command
python web2py.py -K myapp
Now I want to add another function which will start every hour to do some background work.
What would you recommend and how to add it to scheduler because if i add anything to my line of code my initial task --> exe app is not started
thank you
best regards
Nico de Groot
Looking at your code you posted earlier at http://stackoverflow.com/questions/34661782/web2py-function-not-triggered-on-user-request/34895532#34895532 ou have a task running the engine. This task is scheduled by adding it adding it to the scheduler. You can create a second task and add this task using a one-time controller, a script, or at application start time.
Nico de Groot
--
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 a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/FK1ygjNNjDU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
from gluon.scheduler import Scheduler
def runWoshiEngine(scriptId, path):
# import os, sys
# import time
import subprocess
print "runWoshiEngine in progress......"
p = subprocess.Popen(['woshi_engine.exe', scriptId], shell=True, stdout = subprocess.PIPE, cwd=path)
return dict(status = 1)
def saveIdOut(a,b):
print b
print "haha " + a
print "----"
return dict(status = 1)
scheduler = Scheduler(db, tasks = dict(runWoshiEngine = runWoshiEngine,saveIdOut=saveIdOut ) ,heartbeat = 1)
task = scheduler.queue_task(saveIdOut, [1,2], start_time=now, # datetime
stop_time=None, # datetime
timeout = 60, # seconds
repeats=6)
--
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 a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/FK1ygjNNjDU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Ok thanxHow and where do I add one time controller, or application start?my task will be executed once per hour
Traceback (most recent call last):
File "/Users/ncdegroot/web2py/gluon/scheduler.py", line 315, in executor
result = dumps(_function(*args, **vars))
File "applications/welcome/models/scheduler.py", line 16, in saveIdOut
print "haha " + a
TypeError: cannot concatenate 'str' and 'int' objects
print 'haha' + b
print 'haha'+str(i)
On Friday, November 11, 2016 at 4:15:46 AM UTC-8, Yebach wrote:Ok thanxHow and where do I add one time controller, or application start?my task will be executed once per hour
Was the example I pointed not clear? What questions did you have after reading it? What could I explain better?
/dps
--
--
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 a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/FK1ygjNNjDU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Thank you guys. I finally made it. I did not quite understand the whole scheduler process but i am now getting there.Thank you again
def saveIdOut():
try:
#demo koda
#poberem statuse
db_status = db(db.scripts.sc_status == 11).select(db.scripts.id).as_list()
#ggrem v mapo in pogledam katere skripte ki imajo status 11 se dejansko izvajajo
for rec in db_status:
scriptId = rec["id"]
outPath = os.path.join(request.folder, 'engine', 'e1', str(scriptId) + '.out')
#preverim če obstaja datoteka
if os.path.isfile(outPath):
#če obstaja jo shranim v sc_engine_output
#sparsamo out datoteko da jo lahko damo v tabelo result
out = readOutFile(str(scriptId))
#Vnesemo podatke v tabelo script
db(db.scripts.id == scriptId).update(sc_engine_output = out)
print db._lastsql
print "out datoteka za scripto %s, arhivirana" % (str(scriptId))
db.commit()
return dict(status = 1)
except Exception, e:
exc_type, exc_obj, exc_tb = sys.exc_info()
fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
print(exc_type, fname, exc_tb.tb_lineno)
print e.__doc__
print e.message
return dict(status = 666)
in my controler
def save_outs():
"""
for running scheduler
python web2py.py --nogui --no-banner -K woshiweb -D 0
1 hour = 3600 seconds # for period
10 minutes = 600 seconds # for timeout
"""
import datetime
now = datetime.datetime.now()
start_now = datetime.datetime.now()
stop_time_now = (start_now + datetime.timedelta(days = 1))
scheduler.queue_task(saveIdOut, start_time = start_now,
next_run_time = start_now, stop_time = stop_time_now,
repeats = 0, retry_failed = 2, period = 30, timeout = 15)
print "Funkcija za arhiviranje outov AKTIVIRANA...."
print "Glej scheduler tabele v postgresu"
session.flash = T("Task save_outs Queued")
redirect(URL('index.html'))
--
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 a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/FK1ygjNNjDU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
--Lep pozdravVid Ogris
--
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 a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/FK1ygjNNjDU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
To unsubscribe from this group and all its topics, send an email to web2py+unsubscribe@googlegroups.com.
----Lep pozdravVid Ogris
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 a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/FK1ygjNNjDU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
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 a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/FK1ygjNNjDU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+unsubscribe@googlegroups.com.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
----Lep pozdravVid Ogris
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 a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/FK1ygjNNjDU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
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 a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/FK1ygjNNjDU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
--Lep pozdravVid Ogris
--
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 a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/FK1ygjNNjDU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.