3
# Copyright 2010 Canonical Ltd. This software is licensed under the
4
# GNU Affero General Public License version 3 (see the file LICENSE).
6
"""Calculate database replication lag and cache it."""
18
from canonical.database.sqlbase import connect, ISOLATION_LEVEL_AUTOCOMMIT
19
from canonical.launchpad.scripts import db_options, logger
20
from lp.scripts.helpers import LPOptionParser
24
parser = LPOptionParser()
27
"-s", "--sleep", dest="sleep", type="int", default=5,
28
metavar="SECS", help="Wait SECS seconds between refreshes.")
30
(options, args) = parser.parse_args(args)
32
parser.error("Too many arguments.")
38
con = connect(user="lagmon", isolation=ISOLATION_LEVEL_AUTOCOMMIT)
41
cur.execute("SELECT update_replication_lag_cache()")
45
log.error("update_replication_lag_cache() failed.")
46
time.sleep(options.sleep)
47
except psycopg2.Error, x:
48
log.error("%s. Retrying.", str(x).strip())
49
time.sleep(options.sleep)
52
if __name__ == '__main__':