]> git.openstreetmap.org Git - nominatim.git/blobdiff - src/nominatim_db/clicmd/replication.py
Merge pull request #3519 from lonvia/api-error-handling
[nominatim.git] / src / nominatim_db / clicmd / replication.py
index 6fc4dc302a0921cb86fd844a8d52aca0dda65329..ba4c7730b44a6ef6782bd651a25b53abb56748fa 100644 (file)
@@ -13,10 +13,11 @@ import datetime as dt
 import logging
 import socket
 import time
 import logging
 import socket
 import time
+import asyncio
 
 
-from nominatim_core.db import status
-from nominatim_core.db.connection import connect
-from nominatim_core.errors import UsageError
+from ..db import status
+from ..db.connection import connect
+from ..errors import UsageError
 from .args import NominatimArgs
 
 LOG = logging.getLogger()
 from .args import NominatimArgs
 
 LOG = logging.getLogger()
@@ -116,14 +117,14 @@ class UpdateReplication:
            and update_interval < 86400:
             LOG.fatal("Update interval too low for download.geofabrik.de.\n"
                       "Please check install documentation "
            and update_interval < 86400:
             LOG.fatal("Update interval too low for download.geofabrik.de.\n"
                       "Please check install documentation "
-                      "(https://nominatim.org/release-docs/latest/admin/Import-and-Update#"
+                      "(https://nominatim.org/release-docs/latest/admin/Update/#"
                       "setting-up-the-update-process).")
             raise UsageError("Invalid replication update interval setting.")
 
         return update_interval
 
 
                       "setting-up-the-update-process).")
             raise UsageError("Invalid replication update interval setting.")
 
         return update_interval
 
 
-    def _update(self, args: NominatimArgs) -> None:
+    async def _update(self, args: NominatimArgs) -> None:
         # pylint: disable=too-many-locals
         from ..tools import replication
         from ..indexer.indexer import Indexer
         # pylint: disable=too-many-locals
         from ..tools import replication
         from ..indexer.indexer import Indexer
@@ -161,7 +162,7 @@ class UpdateReplication:
 
             if state is not replication.UpdateState.NO_CHANGES and args.do_index:
                 index_start = dt.datetime.now(dt.timezone.utc)
 
             if state is not replication.UpdateState.NO_CHANGES and args.do_index:
                 index_start = dt.datetime.now(dt.timezone.utc)
-                indexer.index_full(analyse=False)
+                await indexer.index_full(analyse=False)
 
                 with connect(dsn) as conn:
                     status.set_indexed(conn, True)
 
                 with connect(dsn) as conn:
                     status.set_indexed(conn, True)
@@ -172,8 +173,7 @@ class UpdateReplication:
 
             if state is replication.UpdateState.NO_CHANGES and \
                args.catch_up or update_interval > 40*60:
 
             if state is replication.UpdateState.NO_CHANGES and \
                args.catch_up or update_interval > 40*60:
-                while indexer.has_pending():
-                    indexer.index_full(analyse=False)
+                await indexer.index_full(analyse=False)
 
             if LOG.isEnabledFor(logging.WARNING):
                 assert batchdate is not None
 
             if LOG.isEnabledFor(logging.WARNING):
                 assert batchdate is not None
@@ -196,5 +196,5 @@ class UpdateReplication:
         if args.check_for_updates:
             return self._check_for_updates(args)
 
         if args.check_for_updates:
             return self._check_for_updates(args)
 
-        self._update(args)
+        asyncio.run(self._update(args))
         return 0
         return 0