fixes
This commit is contained in:
parent
b23196b233
commit
4ea2e8460b
|
@ -7,15 +7,22 @@ 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 = "задача запущена"
|
||||
|
||||
db.session.commit()
|
||||
|
|
@ -97,7 +97,9 @@ def start_task(task_id: int):
|
|||
add_to_group_task.delay(task_id=task_id)
|
||||
|
||||
case 'parse':
|
||||
try:
|
||||
parse_users_task.run(task_id=task_id)
|
||||
finally:
|
||||
delete_task(task_id)
|
||||
|
||||
return '', 204
|
||||
|
|
|
@ -45,9 +45,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):
|
||||
task: Task = Task.query.get_or_404(task_id)
|
||||
|
|
|
@ -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