I have a thread in daemons that executes a loop and executes the following request:
try:
newsletter = self.session.query(models.Newsletter).\
filter(models.Newsletter.status == 'PROCESSING').\
limit(1).one()
except sa.orm.exc.NoResultFound:
self.logger.debug('No PROCESSING newsletters found. Sleeping...')
self.sleep()
return
If the sleep method simply stops executing this thread for the configured time, and the return statement returns to the main loop. However, I found that if I change the status of the newsletter to “PROCESSING” while the daemon is running, nothing happens, i.e. the request still calls NoResultFound. However, if I restart the daemon, it will find the newsletter. Therefore, I see that the results of this query should be cached. What can I do to invalidate the cache? session.expire_all () does not work. I could also create a new Session () object at each iteration, but I don't know if this applies well to system resources.
source
share