I'm integrating Huey with a simple pyramid app. I'm not using a global SQLAlchemy session in the app (I'm making use of the latest alchemy scaffold). However, there seems to be no other straightforward way to provide a session to periodic tasks.
from huey import RedisHuey
huey = RedisHuey(password=os.environ.get('REDIS_PASSWORD', ''))
DBSession = scoped_session(sessionmaker())
@huey.periodic_task(crontab(minute='*/1'))
def notify_not_confirmed_assignments():
# TODO: Use a non-global DB session
assignments = DBSession.query(Assignment).filter_by(date=next_date).all()
Does Huey offer hooks to close the DB connection on task completion? What is the best way to provide a thread-safe connection to these tasks?
Thanks in advance!