fixes
This commit is contained in:
parent
b23196b233
commit
4ea2e8460b
|
@ -6,16 +6,23 @@ def success_state(task_id):
|
|||
|
||||
task.status = "SUCCESS"
|
||||
task.status_message = "задача выполнена успешно"
|
||||
|
||||
db.session.commit()
|
||||
|
||||
def failure_state(task_id, exception):
|
||||
task = Task.query.get(task_id)
|
||||
|
||||
task.status = "FAILURE"
|
||||
task.status_message = f"произошла ошибка {str(exception)}"
|
||||
|
||||
|
||||
db.session.commit()
|
||||
|
||||
def run_state(task_id, task_record_id):
|
||||
task = Task.query.get(task_record_id)
|
||||
|
||||
task.task_id = task_id
|
||||
task.status = "RUNNING"
|
||||
task.status_message = "задача запущена"
|
||||
task.status_message = "задача запущена"
|
||||
|
||||
db.session.commit()
|
||||
|
|
@ -97,8 +97,10 @@ def start_task(task_id: int):
|
|||
add_to_group_task.delay(task_id=task_id)
|
||||
|
||||
case 'parse':
|
||||
parse_users_task.run(task_id=task_id)
|
||||
delete_task(task_id)
|
||||
try:
|
||||
parse_users_task.run(task_id=task_id)
|
||||
finally:
|
||||
delete_task(task_id)
|
||||
|
||||
return '', 204
|
||||
|
||||
|
|
|
@ -44,9 +44,6 @@ def add_to_group_task(self, task_id: int):
|
|||
|
||||
else:
|
||||
success_state(task_id)
|
||||
|
||||
finally:
|
||||
db.session.commit()
|
||||
|
||||
@shared_task(bind=True)
|
||||
def parse_users_task(self, task_id: int):
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import asyncio
|
||||
|
||||
from loguru import logger
|
||||
|
||||
from app.extensions import db
|
||||
from paper.client import PaperClient
|
||||
from paper.errors import IgnoreException, NeedPasswordException, UserPrivacyException
|
||||
|
||||
|
@ -13,8 +13,6 @@ class PaperParser:
|
|||
|
||||
self.client = PaperClient(session)
|
||||
|
||||
self.users_to_delete = []
|
||||
|
||||
async def invite_users(self, users, group, task):
|
||||
await self.client.invite_self(group)
|
||||
|
||||
|
@ -34,6 +32,7 @@ class PaperParser:
|
|||
except (UserPrivacyException, IgnoreException):
|
||||
logger.warning(f"Exception occurred. Marking {user.username} for deletion...")
|
||||
user.delete = True
|
||||
db.session.commit()
|
||||
|
||||
finally:
|
||||
if not task.is_aborted():
|
||||
|
@ -56,8 +55,9 @@ class PaperParser:
|
|||
await self.client.send_message(user, message, file)
|
||||
|
||||
except (UserPrivacyException, IgnoreException):
|
||||
self.users_to_delete.append(user)
|
||||
logger.warning("Exception occurred. Skipping user...")
|
||||
logger.warning(f"Exception occurred. Marking {user.username} for deletion...")
|
||||
user.delete = True
|
||||
db.session.commit()
|
||||
|
||||
finally:
|
||||
if not task.is_aborted():
|
||||
|
|
Loading…
Reference in New Issue