| 81 | self._log.error(f"{traceback.format_exc()}") |
| 82 | |
| 83 | async def get_tasks(self): |
| 84 | try: |
| 85 | resp_json = await self._api.get_tasks() |
| 86 | |
| 87 | collected_tasks = [] |
| 88 | for section in resp_json: |
| 89 | collected_tasks.extend(section.get('tasks', [])) |
| 90 | for sub_section in section.get("subSections"): |
| 91 | collected_tasks.extend(sub_section.get('tasks', [])) |
| 92 | |
| 93 | for task in collected_tasks: |
| 94 | if task.get("subTasks"): |
| 95 | collected_tasks.extend(task.get("subTasks")) |
| 96 | |
| 97 | unique_tasks = {} |
| 98 | |
| 99 | task_types = ("SOCIAL_SUBSCRIPTION", "INTERNAL", "SOCIAL_MEDIA_CHECK") |
| 100 | for task in collected_tasks: |
| 101 | if task['status'] == "NOT_STARTED" and task['type'] in task_types or \ |
| 102 | task['status'] == "READY_FOR_CLAIM" or \ |
| 103 | task['status'] == "READY_FOR_VERIFY" and task['validationType'] == 'KEYWORD': |
| 104 | unique_tasks.update({task.get("id"): task}) |
| 105 | self._log.debug(f"Loaded {len(unique_tasks.keys())} tasks") |
| 106 | return unique_tasks.values() |
| 107 | except Exception as error: |
| 108 | self._log.error(f"Get tasks error {error}") |
| 109 | return [] |
| 110 | |
| 111 | async def check_tasks(self) -> bool: |
| 112 | if settings.AUTO_TASKS is not True: |