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)