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