Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to force analysis even if resource has not changed #205

Merged
merged 7 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
6 changes: 4 additions & 2 deletions udata_hydra/analysis/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ class Change(Enum):
log = logging.getLogger("udata-hydra")


async def analyse_resource(check_id: int, is_first_check: bool) -> None:
async def analyse_resource(
check_id: int, is_first_check: bool, force_analysis: bool = False
) -> None:
"""
Perform analysis on the resource designated by check_id:
- change analysis
Expand Down Expand Up @@ -107,7 +109,7 @@ async def analyse_resource(check_id: int, is_first_check: bool) -> None:

analysis_results = {**dl_analysis, **(change_payload or {})}

if change_status == Change.HAS_CHANGED or is_first_check:
if change_status == Change.HAS_CHANGED or is_first_check or force_analysis:
if is_tabular and tmp_file:
# Change status to TO_ANALYSE_CSV
await Resource.update(resource_id, data={"status": "TO_ANALYSE_CSV"})
Expand Down
3 changes: 2 additions & 1 deletion udata_hydra/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ async def crawl_url(url: str, method: str = "get"):


@cli
async def check_resource(resource_id: str, method: str = "get"):
async def check_resource(resource_id: str, method: str = "get", force_analysis: bool = False):
Pierlou marked this conversation as resolved.
Show resolved Hide resolved
"""Trigger a complete check for a given resource_id"""
resource: asyncpg.Record | None = await Resource.get(resource_id)
if not resource:
Expand All @@ -149,6 +149,7 @@ async def check_resource(resource_id: str, method: str = "get"):
resource_id=resource_id,
session=session,
method=method,
force_analysis=force_analysis,
worker_priority="high",
)

Expand Down
8 changes: 7 additions & 1 deletion udata_hydra/crawl/check_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ async def check_resource(
url: str,
resource_id: str,
session,
force_analysis: bool = False,
Pierlou marked this conversation as resolved.
Show resolved Hide resolved
sleep: float = 0,
method: str = "head",
worker_priority: str = "default",
Expand Down Expand Up @@ -101,7 +102,12 @@ async def check_resource(
end = time.time()
if method != "get" and not has_nice_head(resp):
return await check_resource(
url, resource_id, session, method="get", worker_priority=worker_priority
url,
resource_id,
session,
force_analysis=force_analysis,
method="get",
worker_priority=worker_priority,
)
resp.raise_for_status()

Expand Down
7 changes: 6 additions & 1 deletion udata_hydra/routes/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ async def create_check(request: web.Request) -> web.Response:
try:
payload: dict = await request.json()
resource_id: str = payload["resource_id"]
force_analysis: bool = payload.get("force_analysis", False)
Pierlou marked this conversation as resolved.
Show resolved Hide resolved
except Exception as err:
raise web.HTTPBadRequest(text=json.dumps({"error": str(err)}))

Expand All @@ -80,7 +81,11 @@ async def create_check(request: web.Request) -> web.Response:
timeout=None, headers={"user-agent": config.USER_AGENT}
) as session:
status: str = await check_resource(
url=url, resource_id=resource_id, session=session, worker_priority="high"
url=url,
resource_id=resource_id,
force_analysis=force_analysis,
session=session,
worker_priority="high",
)
context.monitor().refresh(status)

Expand Down