]> git.openstreetmap.org Git - nominatim.git/blobdiff - src/nominatim_db/clicmd/replication.py
switch actions to pip-based install
[nominatim.git] / src / nominatim_db / clicmd / replication.py
index 6fc4dc302a0921cb86fd844a8d52aca0dda65329..da60eafe1a49a632d652bae7439690d11d732fbc 100644 (file)
@@ -13,18 +13,15 @@ import datetime as dt
 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()
 
-# Do not repeat documentation of subcommand classes.
-# pylint: disable=C0111
-# Using non-top-level imports to make pyosmium optional for replication only.
-# pylint: disable=C0415
 
 class UpdateReplication:
     """\
@@ -70,7 +67,6 @@ class UpdateReplication:
         group.add_argument('--socket-timeout', dest='socket_timeout', type=int, default=60,
                            help='Set timeout for file downloads')
 
-
     def _init_replication(self, args: NominatimArgs) -> int:
         from ..tools import replication, refresh
 
@@ -83,7 +79,6 @@ class UpdateReplication:
                 refresh.create_functions(conn, args.config, True, False)
         return 0
 
-
     def _check_for_updates(self, args: NominatimArgs) -> int:
         from ..tools import replication
 
@@ -91,7 +86,6 @@ class UpdateReplication:
             return replication.check_for_updates(conn, base_url=args.config.REPLICATION_URL,
                                                  socket_timeout=args.socket_timeout)
 
-
     def _report_update(self, batchdate: dt.datetime,
                        start_import: dt.datetime,
                        start_index: Optional[dt.datetime]) -> None:
@@ -105,7 +99,6 @@ class UpdateReplication:
                     round_time(end - start_import),
                     round_time(end - batchdate))
 
-
     def _compute_update_interval(self, args: NominatimArgs) -> int:
         if args.catch_up:
             return 0
@@ -116,15 +109,13 @@ class UpdateReplication:
            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
 
-
-    def _update(self, args: NominatimArgs) -> None:
-        # pylint: disable=too-many-locals
+    async def _update(self, args: NominatimArgs) -> None:
         from ..tools import replication
         from ..indexer.indexer import Indexer
         from ..tokenizer import factory as tokenizer_factory
@@ -161,7 +152,7 @@ class UpdateReplication:
 
             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)
@@ -172,8 +163,7 @@ class UpdateReplication:
 
             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
@@ -186,7 +176,6 @@ class UpdateReplication:
                 LOG.warning("No new changes. Sleeping for %d sec.", recheck_interval)
                 time.sleep(recheck_interval)
 
-
     def run(self, args: NominatimArgs) -> int:
         socket.setdefaulttimeout(args.socket_timeout)
 
@@ -196,5 +185,5 @@ class UpdateReplication:
         if args.check_for_updates:
             return self._check_for_updates(args)
 
-        self._update(args)
+        asyncio.run(self._update(args))
         return 0