Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion api/routes/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from fastapi import APIRouter, Depends, Query, Path

from api.dependencies import get_async_core
from collector_db.DTOs.GetTaskStatusResponseInfo import GetTaskStatusResponseInfo
from collector_db.DTOs.TaskInfo import TaskInfo
from collector_db.enums import TaskType
from core.AsyncCore import AsyncCore
Expand Down Expand Up @@ -39,11 +40,19 @@
task_status=task_status
)

@task_router.get("/status")
async def get_task_status(

Check warning on line 44 in api/routes/task.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] api/routes/task.py#L44 <103>

Missing docstring in public function
Raw output
./api/routes/task.py:44:1: D103 Missing docstring in public function
async_core: AsyncCore = Depends(get_async_core),
access_info: AccessInfo = Depends(get_access_info)

Check warning on line 46 in api/routes/task.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] api/routes/task.py#L46 <100>

Unused argument 'access_info'
Raw output
./api/routes/task.py:46:9: U100 Unused argument 'access_info'
) -> GetTaskStatusResponseInfo:
return await async_core.get_current_task_status()

@task_router.get("/{task_id}")
async def get_task_info(
task_id: int = Path(description="The task id"),
async_core: AsyncCore = Depends(get_async_core),
access_info: AccessInfo = Depends(get_access_info)
) -> TaskInfo:
return await async_core.get_task_info(task_id)
return await async_core.get_task_info(task_id)


Check warning on line 58 in api/routes/task.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] api/routes/task.py#L58 <391>

blank line at end of file
Raw output
./api/routes/task.py:58:1: W391 blank line at end of file
7 changes: 7 additions & 0 deletions collector_db/DTOs/GetTaskStatusResponseInfo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from pydantic import BaseModel

Check warning on line 1 in collector_db/DTOs/GetTaskStatusResponseInfo.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] collector_db/DTOs/GetTaskStatusResponseInfo.py#L1 <100>

Missing docstring in public module
Raw output
./collector_db/DTOs/GetTaskStatusResponseInfo.py:1:1: D100 Missing docstring in public module

from collector_db.enums import TaskType


class GetTaskStatusResponseInfo(BaseModel):

Check warning on line 6 in collector_db/DTOs/GetTaskStatusResponseInfo.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] collector_db/DTOs/GetTaskStatusResponseInfo.py#L6 <101>

Missing docstring in public class
Raw output
./collector_db/DTOs/GetTaskStatusResponseInfo.py:6:1: D101 Missing docstring in public class
status: TaskType

Check warning on line 7 in collector_db/DTOs/GetTaskStatusResponseInfo.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] collector_db/DTOs/GetTaskStatusResponseInfo.py#L7 <292>

no newline at end of file
Raw output
./collector_db/DTOs/GetTaskStatusResponseInfo.py:7:21: W292 no newline at end of file
1 change: 1 addition & 0 deletions collector_db/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class TaskType(PyEnum):
RECORD_TYPE = "Record Type"
AGENCY_IDENTIFICATION = "Agency Identification"
MISC_METADATA = "Misc Metadata"
IDLE = "Idle"

class PGEnum(TypeDecorator):
impl = postgresql.ENUM
Expand Down
3 changes: 3 additions & 0 deletions core/AsyncCore.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from collector_db.AsyncDatabaseClient import AsyncDatabaseClient
from collector_db.DTOs.BatchInfo import BatchInfo
from collector_db.DTOs.GetTaskStatusResponseInfo import GetTaskStatusResponseInfo
from collector_db.enums import TaskType
from collector_manager.AsyncCollectorManager import AsyncCollectorManager
from collector_manager.enums import CollectorType
Expand Down Expand Up @@ -87,6 +88,8 @@
)

# endregion
async def get_current_task_status(self) -> GetTaskStatusResponseInfo:

Check warning on line 91 in core/AsyncCore.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] core/AsyncCore.py#L91 <102>

Missing docstring in public method
Raw output
./core/AsyncCore.py:91:1: D102 Missing docstring in public method
return GetTaskStatusResponseInfo(status=self.task_manager.task_status)

async def run_tasks(self):
await self.task_manager.trigger_task_run()
Expand Down
10 changes: 8 additions & 2 deletions core/TaskManager.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
from typing import Optional

Check warning on line 2 in core/TaskManager.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] core/TaskManager.py#L2 <401>

'typing.Optional' imported but unused
Raw output
./core/TaskManager.py:2:1: F401 'typing.Optional' imported but unused

from agency_identifier.MuckrockAPIInterface import MuckrockAPIInterface
from collector_db.AsyncDatabaseClient import AsyncDatabaseClient
Expand Down Expand Up @@ -44,12 +45,12 @@
self.logger.addHandler(logging.StreamHandler())
self.logger.setLevel(logging.INFO)
self.task_trigger = FunctionTrigger(self.run_tasks)
self.task_status: TaskType = TaskType.IDLE



#region Task Operators
async def get_url_html_task_operator(self):
self.logger.info("Running URL HTML Task")
operator = URLHTMLTaskOperator(
adb_client=self.adb_client,
url_request_interface=self.url_request_interface,
Expand All @@ -58,7 +59,6 @@
return operator

async def get_url_relevance_huggingface_task_operator(self):
self.logger.info("Running URL Relevance Huggingface Task")
operator = URLRelevanceHuggingfaceTaskOperator(
adb_client=self.adb_client,
huggingface_interface=self.huggingface_interface
Expand Down Expand Up @@ -106,13 +106,18 @@
#endregion

#region Tasks
async def set_task_status(self, task_type: TaskType):

Check warning on line 109 in core/TaskManager.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] core/TaskManager.py#L109 <102>

Missing docstring in public method
Raw output
./core/TaskManager.py:109:1: D102 Missing docstring in public method
self.task_status = task_type

async def run_tasks(self):
operators = await self.get_task_operators()
count = 0
for operator in operators:
await self.set_task_status(task_type=operator.task_type)

meets_prereq = await operator.meets_task_prerequisites()
while meets_prereq:
print(f"Running {operator.task_type.value} Task")
if count > TASK_REPEAT_THRESHOLD:
self.discord_poster.post_to_discord(
message=f"Task {operator.task_type.value} has been run"
Expand All @@ -124,6 +129,7 @@
await self.conclude_task(run_info)
count += 1
meets_prereq = await operator.meets_task_prerequisites()
await self.set_task_status(task_type=TaskType.IDLE)

async def trigger_task_run(self):
await self.task_trigger.trigger_or_rerun()
Expand Down
1 change: 0 additions & 1 deletion core/classes/URLHTMLTaskOperator.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ async def meets_task_prerequisites(self):
return await self.adb_client.has_pending_urls_without_html_data()

async def inner_task_logic(self):
print("Running URL HTML Task...")
tdos = await self.get_pending_urls_without_html_data()
url_ids = [task_info.url_info.id for task_info in tdos]
await self.link_urls_to_task(url_ids=url_ids)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from starlette.testclient import TestClient

from collector_db.DTOs.BatchInfo import BatchInfo
from collector_db.DTOs.GetTaskStatusResponseInfo import GetTaskStatusResponseInfo
from collector_db.DTOs.TaskInfo import TaskInfo
from collector_db.enums import TaskType
from collector_manager.DTOs.ExampleInputDTO import ExampleInputDTO
Expand Down Expand Up @@ -281,4 +282,10 @@
url=f"/review/reject-source",
json=review_info.model_dump(mode='json')
)
return GetNextURLForFinalReviewOuterResponse(**data)
return GetNextURLForFinalReviewOuterResponse(**data)

async def get_current_task_status(self) -> GetTaskStatusResponseInfo:

Check warning on line 287 in tests/test_automated/integration/api/helpers/RequestValidator.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] tests/test_automated/integration/api/helpers/RequestValidator.py#L287 <102>

Missing docstring in public method
Raw output
./tests/test_automated/integration/api/helpers/RequestValidator.py:287:1: D102 Missing docstring in public method
data = self.get(
url=f"/task/status"

Check warning on line 289 in tests/test_automated/integration/api/helpers/RequestValidator.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] tests/test_automated/integration/api/helpers/RequestValidator.py#L289 <541>

f-string is missing placeholders
Raw output
./tests/test_automated/integration/api/helpers/RequestValidator.py:289:17: F541 f-string is missing placeholders
)
return GetTaskStatusResponseInfo(**data)

Check warning on line 291 in tests/test_automated/integration/api/helpers/RequestValidator.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] tests/test_automated/integration/api/helpers/RequestValidator.py#L291 <292>

no newline at end of file
Raw output
./tests/test_automated/integration/api/helpers/RequestValidator.py:291:49: W292 no newline at end of file
14 changes: 14 additions & 0 deletions tests/test_automated/integration/api/test_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,17 @@
assert task.type == TaskType.HTML
assert task.url_count == 3
assert task.url_error_count == 1

@pytest.mark.asyncio
async def test_get_task_status(api_test_helper):

Check warning on line 44 in tests/test_automated/integration/api/test_task.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] tests/test_automated/integration/api/test_task.py#L44 <103>

Missing docstring in public function
Raw output
./tests/test_automated/integration/api/test_task.py:44:1: D103 Missing docstring in public function
ath = api_test_helper

response = await ath.request_validator.get_current_task_status()

assert response.status == TaskType.IDLE

for task in [task for task in TaskType]:
await ath.async_core.task_manager.set_task_status(task)
response = await ath.request_validator.get_current_task_status()

assert response.status == task