5
5
import sys
6
6
import time
7
7
import traceback
8
- from datetime import datetime
9
- from datetime import timedelta
10
- from typing import Optional
8
+ from datetime import datetime , timedelta
9
+ from typing import Annotated , Optional
11
10
from urllib .error import HTTPError
12
- from zoneinfo import ZoneInfo
13
11
14
12
import httpx
15
13
import i18n
16
14
from dateutil import parser as du_parser
17
15
from folio_uuid .folio_namespaces import FOLIONamespaces
16
+ from pydantic import Field
17
+ from zoneinfo import ZoneInfo
18
18
19
19
from folio_migration_tools .circulation_helper import CirculationHelper
20
20
from folio_migration_tools .helper import Helper
21
- from folio_migration_tools .library_configuration import FileDefinition
22
- from folio_migration_tools .library_configuration import FolioRelease
23
- from folio_migration_tools .library_configuration import LibraryConfiguration
21
+ from folio_migration_tools .library_configuration import (
22
+ FileDefinition ,
23
+ FolioRelease ,
24
+ LibraryConfiguration ,
25
+ )
24
26
from folio_migration_tools .mapping_file_transformation .mapping_file_mapper_base import (
25
27
MappingFileMapperBase ,
26
28
)
@@ -40,6 +42,13 @@ class TaskConfiguration(AbstractTaskConfiguration):
40
42
open_loans_files : list [FileDefinition ]
41
43
fallback_service_point_id : str
42
44
starting_row : Optional [int ] = 1
45
+ sync_patron_blocks : Annotated [
46
+ bool ,
47
+ Field (
48
+ title = "Sync patron blocks" ,
49
+ descriptions = "If set to true, a sync job will run for automated patron blocks"
50
+ )
51
+ ] = False
43
52
item_files : Optional [list [FileDefinition ]] = []
44
53
patron_files : Optional [list [FileDefinition ]] = []
45
54
@@ -280,6 +289,25 @@ def wrap_up(self):
280
289
i18n .t ("Loans migration report" ), report_file , self .start_datetime
281
290
)
282
291
self .clean_out_empty_logs ()
292
+ self .sync_patron_blocks ()
293
+
294
+ def sync_patron_blocks (self ):
295
+ if self .task_configuration .sync_patron_blocks :
296
+ job_payload = {
297
+ "scope" : "full" ,
298
+ }
299
+ try :
300
+ sync_job = self .folio_client .folio_post ("/automated-patron-blocks/synchronization/job" , job_payload )
301
+ print (f"Sync job created:\n { json .dumps (sync_job )} " )
302
+ except Exception as ee :
303
+ if hasattr (ee , "response" ):
304
+ logging .error (
305
+ f"Failed to sync patron blocks: { ee .response .status_code } { ee .response .text } "
306
+ )
307
+ else :
308
+ logging .error (f"Failed to sync patron blocks: { ee } " )
309
+ else :
310
+ logging .info ("Skipping patron block sync" )
283
311
284
312
def write_failed_loans_to_file (self ):
285
313
csv_columns = [
0 commit comments