I had a similar thought but when I do DBSession.flush() in the
tgscheduler module it does nothing so then the initial add/set to 1
never happens. It seems that the only time it will actually write to
the DB is when transaction.commit() is called ignoring the flush.
Here is the entire module minus the extra "stuff"...
#!/usr/bin/env python
from tgscheduler import start_scheduler
import transaction
from tgscheduler.scheduler import add_interval_task, add_weekday_task,
add_single_task
import sys
import os
import logging
from datetime import datetime
from pel_pickship.model import DBSession
from pel_pickship.model.auth import Order, OrderLine, Flag
log = logging.getLogger(__name__)
def importOrders():
import_flag =
DBSession.query(Flag).filter(Flag.flag_name=='import_flag').first()
if not import_flag:
import_flag = Flag('import_flag')
DBSession.add(import_flag)
import_flag.flag_value = 1
transaction.commit()
.... #stuff
import_flag.flag_value = 0
transaction.commit()
def schedule():
""" start scheduler and setup recurring tasks """
if "shell" in sys.argv: # disable cron in paster shell mode
return
log.info("Starting Scheduler Manager")
start_scheduler()
#add_interval_task(action=importOrders, taskname="importOrders",
interval=5, initialdelay=0)
add_single_task(action=importOrders,initialdelay=0)