From 4bdf9e76a616667366d1f8aed3ec547381fcd542 Mon Sep 17 00:00:00 2001 From: a76yyyy Date: Sat, 9 Mar 2024 22:37:38 +0800 Subject: [PATCH] =?UTF-8?q?Bugfix(worker):=20=F0=9F=90=9B=20=E6=A8=A1?= =?UTF-8?q?=E6=9D=BF=E6=88=90=E5=8A=9F=E5=A4=B1=E8=B4=A5=E6=95=B0=E7=9A=84?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=8B=AC=E7=AB=8B=E8=87=B3=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E6=89=A7=E8=A1=8C=E4=B9=8B=E5=A4=96=20Fix=20qd-today/qd#511?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- worker.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/worker.py b/worker.py index 4e49c763de5..904130001e8 100644 --- a/worker.py +++ b/worker.py @@ -255,7 +255,6 @@ async def do(self, task): mtime=time.time(), next=next, sql_session=sql_session) - await self.db.tpl.incr_success(tpl['id'], sql_session=sql_session) t = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') title = f"QD定时任务 {tpl['sitename']}-{task['note']} 成功" @@ -305,11 +304,17 @@ async def do(self, task): mtime=time.time(), next=next, sql_session=sql_session) - await self.db.tpl.incr_failed(tpl['id'], sql_session=sql_session) logger_worker.error('taskid:%d tplid:%d failed! %.4fs \r\n%s', task['id'], task['tplid'], time.perf_counter( ) - start, str(e).replace('\\r\\n', '\r\n')) + async with self.db.transaction() as sql_session: + if tpl and tpl.get('id'): + if is_success: + await self.db.tpl.incr_success(tpl['id'], sql_session=sql_session) + else: + await self.db.tpl.incr_failed(tpl['id'], sql_session=sql_session) + if should_push: try: pushtool = Pusher(self.db, sql_session=sql_session)