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

Fix log messages #53

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
26 changes: 15 additions & 11 deletions prefect_meemoo/mediahaven/tasks.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import json
import time
from typing import List

from mediahaven import MediaHaven
from mediahaven.mediahaven import MediaHavenException
from mediahaven.oauth2 import RequestTokenError
from mediahaven.resources.base_resource import MediaHavenPageObject
from mergedeep import merge
from prefect import flow, get_run_logger, task
from prefect.blocks.system import JSON
from prefect.filesystems import LocalFileSystem

from prefect_meemoo.mediahaven.credentials import MediahavenCredentials

Expand Down Expand Up @@ -179,18 +176,25 @@ def search_records(
query += f" +(LastModifiedDate:{last_modified_date})"
else:
query += f' +(LastModifiedDate:[{last_modified_date} TO *])'
log_record= {
"query": query,
"start_index": start_index,
"nr_of_results": nr_of_results,
"sort": sort
}
try:
records_page = client.records.search(q=query, nrOfResults=nr_of_results, startIndex=start_index, sort=sort)
logger.info(
f"""{{"query": "{query}", "last_modified_date": {last_modified_date}, "start_index": {start_index}, "nr_of_results": {nr_of_results}, "sort": {sort}, "outcome_status": "SUCCESS"}}"""
)
logger.info("TotalNrOfResults: " + str(records_page.page_result.TotalNrOfResults))
return records_page
except Exception as error:
logger.error(
f"""{{ "outcome_status": "FAIL", "status_message": {error}}}"""
)
log_record["outcome_status"] = "FAIL"
log_record["status_message"] = error
logger.error(log_record)
raise error
else:
logger.info({"TotalNrOfResults" : str(records_page.page_result.TotalNrOfResults)})
log_record["outcome_status"] = "SUCCESS"
logger.info(log_record)
return records_page


@task(name="Generate record json")
def generate_record_json(client : MediaHaven, field_flat_key : str, value, merge_strategy : str = None) -> dict:
Expand Down