本文整理汇总了Python中scatterbrainz.model.meta.Session.rollback方法的典型用法代码示例。如果您正苦于以下问题:Python Session.rollback方法的具体用法?Python Session.rollback怎么用?Python Session.rollback使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scatterbrainz.model.meta.Session
的用法示例。
在下文中一共展示了Session.rollback方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
# 需要导入模块: from scatterbrainz.model.meta import Session [as 别名]
# 或者: from scatterbrainz.model.meta.Session import rollback [as 别名]
def run(self):
# Only let one worker run via pg advisory lock
acquired = Session.execute(select([func.pg_try_advisory_lock(importlockid)])).fetchone()[0]
threadid = 'PID ' + str(os.getpid()) + ' thread ' + str(threading.current_thread())
if acquired:
log.info('[shop worker] %s acquired lock, starting..' % threadid)
else:
return
pendingdownloads = False
while True:
try:
downloads = Session.query(ShopDownload) \
.filter(ShopDownload.isdone==False) \
.filter(ShopDownload.failedimport==False) \
.all()
pendingdownloads = len(downloads) != 0
if pendingdownloads:
rtorrent = xmlrpclib.ServerProxy(Config.SHOP_RPC_URL)
for download in downloads:
try:
infohash = download.infohash
iscomplete = rtorrent.d.get_complete(infohash) == 1
if iscomplete:
shopservice.importDownload(download)
except:
exc_type, exc_value, exc_traceback = sys.exc_info()
importtrace = repr(traceback.format_exception(exc_type, exc_value, exc_traceback))
log.error('[shop worker] caught exception in loop ' + importtrace)
Session.rollback()
Session.begin()
download.failedimport = True
download.importtrace = importtrace
Session.commit()
except Exception as e:
log.error('[shop worker] caught exception out of loop ' + repr(e))
Session.rollback()
if pendingdownloads:
time.sleep(10)
else:
time.sleep(30)