Skip to content

Commit

Permalink
Fixes Sync blocks after loan migration #788. Add optional configurati…
Browse files Browse the repository at this point in the history
…on and method for syncing patron blocks. Call in wrap-up method.
  • Loading branch information
bltravis committed Aug 20, 2024
1 parent eae329c commit dfc6512
Showing 1 changed file with 35 additions and 7 deletions.
42 changes: 35 additions & 7 deletions src/folio_migration_tools/migration_tasks/loans_migrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,24 @@
import sys
import time
import traceback
from datetime import datetime
from datetime import timedelta
from typing import Optional
from datetime import datetime, timedelta
from typing import Annotated, Optional
from urllib.error import HTTPError
from zoneinfo import ZoneInfo

import httpx
import i18n
from dateutil import parser as du_parser
from folio_uuid.folio_namespaces import FOLIONamespaces
from pydantic import Field
from zoneinfo import ZoneInfo

from folio_migration_tools.circulation_helper import CirculationHelper
from folio_migration_tools.helper import Helper
from folio_migration_tools.library_configuration import FileDefinition
from folio_migration_tools.library_configuration import FolioRelease
from folio_migration_tools.library_configuration import LibraryConfiguration
from folio_migration_tools.library_configuration import (
FileDefinition,
FolioRelease,
LibraryConfiguration,
)
from folio_migration_tools.mapping_file_transformation.mapping_file_mapper_base import (
MappingFileMapperBase,
)
Expand All @@ -40,6 +42,13 @@ class TaskConfiguration(AbstractTaskConfiguration):
open_loans_files: list[FileDefinition]
fallback_service_point_id: str
starting_row: Optional[int] = 1
sync_patron_blocks: Annotated[
bool,
Field(
title="Sync patron blocks",
descriptions="If set to true, a sync job will run for automated patron blocks"
)
] = False
item_files: Optional[list[FileDefinition]] = []
patron_files: Optional[list[FileDefinition]] = []

Expand Down Expand Up @@ -280,6 +289,25 @@ def wrap_up(self):
i18n.t("Loans migration report"), report_file, self.start_datetime
)
self.clean_out_empty_logs()
self.sync_patron_blocks()

def sync_patron_blocks(self):
if self.task_configuration.sync_patron_blocks:
job_payload = {
"scope": "full",
}
try:
sync_job = self.folio_client.folio_post("/automated-patron-blocks/synchronization/job", job_payload)
print(f"Sync job created:\n{json.dumps(sync_job)}")
except Exception as ee:
if hasattr(ee, "response"):
logging.error(
f"Failed to sync patron blocks: {ee.response.status_code} {ee.response.text}"
)
else:
logging.error(f"Failed to sync patron blocks: {ee}")
else:
logging.info("Skipping patron block sync")

def write_failed_loans_to_file(self):
csv_columns = [
Expand Down

0 comments on commit dfc6512

Please sign in to comment.