2 Functions for updating a database from a replication source.
7 from osmium.replication.server import ReplicationServer
9 from ..db import status
11 LOG = logging.getLogger()
13 def init_replication(conn, base_url):
14 """ Set up replication for the server at the given base URL.
16 LOG.info("Using replication source: %s", base_url)
17 date = status.compute_database_date(conn)
19 # margin of error to make sure we get all data
20 date -= datetime.timedelta(hours=3)
22 repl = ReplicationServer(base_url)
24 seq = repl.timestamp_to_sequence(date)
27 LOG.fatal("Cannot reach the configured replication service '%s'.\n"
28 "Does the URL point to a directory containing OSM update data?",
30 raise RuntimeError("Failed to reach replication service")
32 status.set_status(conn, date=date, seq=seq)
34 LOG.warning("Updates intialised at sequence %s (%s)", seq, date)
37 def check_for_updates(conn, base_url):
38 """ Check if new data is available from the replication service at the
41 _, seq, _ = status.get_status(conn)
44 LOG.error("Replication not set up. "
45 "Please run 'nominatim replication --init' first.")
48 state = ReplicationServer(base_url).get_state_info()
51 LOG.error("Cannot get state for URL %s.", base_url)
54 if state.sequence <= seq:
55 LOG.warning("Database is up to date.")
58 LOG.warning("New data available (%i => %i).", seq, state.sequence)