@@ -80,7 +80,42 @@ def launch_pycsw(pycsw_config, workers=2, reload=False):
8080 except Exception as err :
8181 LOGGER .debug (err )
8282
83- repo = Repository (database , StaticContext ())
83+ if 'source' in pycsw_config ['repository' ]: # load custom repository
84+ rs = pycsw_config ['repository' ]['source' ]
85+ rs_modname , rs_clsname = rs .rsplit ('.' , 1 )
86+
87+ rs_mod = __import__ (rs_modname , globals (), locals (), [rs_clsname ])
88+ rs_cls = getattr (rs_mod , rs_clsname )
89+
90+ try :
91+ connection_done = False
92+ max_attempts = 0
93+ max_retries = pycsw_config ['repository' ].get ('maxretries' , 5 )
94+ while not connection_done and max_attempts <= max_retries :
95+ try :
96+ repo = rs_cls (pycsw_config ['repository' ], StaticContext ())
97+ LOGGER .debug ('Custom repository %s loaded' % pycsw_config ['repository' ]['source' ])
98+ connection_done = True
99+ except Exception as err :
100+ LOGGER .debug (f'Repository not loaded retry connection { max_attempts } : { err } ' )
101+ max_attempts += 1
102+ except Exception as err :
103+ msg = 'Could not load custom repository %s: %s' % (rs , err )
104+ LOGGER .exception (msg )
105+ error = 1
106+ code = 'NoApplicableCode'
107+ locator = 'service'
108+ text = 'Could not initialize repository. Check server logs'
109+
110+ else :
111+ try :
112+ LOGGER .info ('Loading default repository' )
113+ repo = repository .Repository (pycsw_config , StaticContext ())
114+ LOGGER .debug (f'Repository loaded { repo .dbtype } ' )
115+ except Exception as err :
116+ msg = f'Could not load repository { err } '
117+ LOGGER .exception (msg )
118+ raise
84119
85120 repo .ping ()
86121
0 commit comments