kopia lustrzana https://github.com/hholzgra/maposmatic/
Read the OSM database lag directly from the database
This allows us to know if the PostGIS database is up and gets us a lag information that is not refreshed only every minute by a cronjob. Signed-off-by: Maxime Petazzoni <maxime.petazzoni@bulix.org>stable
rodzic
024841e4bc
commit
1adebe9cfb
|
@ -38,17 +38,25 @@ def get_latest_blog_posts():
|
|||
return f.entries[:5]
|
||||
|
||||
def get_osm_database_last_update():
|
||||
"""Returns the timestamp of the last PostGIS database update, which is
|
||||
placed into the maposmatic_admin table in the PostGIS database by the
|
||||
planet-update incremental update script."""
|
||||
|
||||
db = gisdb.get()
|
||||
if db is None:
|
||||
return None
|
||||
|
||||
cursor = db.cursor()
|
||||
|
||||
try:
|
||||
with open(www.settings.GIS_DATABASE_LAG_FILE) as f:
|
||||
try:
|
||||
return datetime.datetime.strptime(
|
||||
'%s' % f.read().strip(),
|
||||
'%Y-%m-%d %H:%M:%S')
|
||||
except ValueError:
|
||||
pass
|
||||
except IOError:
|
||||
cursor.execute("""select last_update from maposmatic_admin""")
|
||||
last_update = cursor.fetchone()
|
||||
if last_update is not None and len(last_update) == 1:
|
||||
return datetime.datetime.strptime(last_update[0], '%Y-%m-%d %H:%M:%S')
|
||||
except:
|
||||
pass
|
||||
|
||||
cursor.close()
|
||||
return None
|
||||
|
||||
def all(request):
|
||||
|
|
|
@ -40,7 +40,7 @@ def get():
|
|||
return _DB
|
||||
|
||||
try:
|
||||
_DB = psycopg2.connect("dbname='%s' user='%s' host='%s' password='%s' port='%s'" %
|
||||
_DB = psycopg2.connect("dbname='%s' user='%s' host='%s' password='%s' port='%s' connection_timeout=1" %
|
||||
(www.settings.GIS_DATABASE_NAME,
|
||||
www.settings.GIS_DATABASE_USER,
|
||||
www.settings.GIS_DATABASE_HOST,
|
||||
|
|
|
@ -87,6 +87,11 @@ form#langsel {
|
|||
margin-right: 1em;
|
||||
}
|
||||
|
||||
p.error {
|
||||
color: red;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
/* Navigation menu */
|
||||
ul#nav {
|
||||
list-style: none;
|
||||
|
|
|
@ -105,9 +105,9 @@
|
|||
<div id="bosmtimestamp">
|
||||
<h3>{% trans "OSM database status" %}</h3>
|
||||
{% if osm_date %}
|
||||
<p>{% blocktrans with osm_date|timesince:utc_now as date %}Lag of MapOSMatic OSM database: {{ date }}.{% endblocktrans %}</p>
|
||||
<p>{% blocktrans with osm_date|timesince:utc_now as date %}Database is online, <span title="{{ osm_date|date:"r" }}">last update {{ date }} ago</span>.{% endblocktrans %}</p>
|
||||
{% else %}
|
||||
<p>{% blocktrans %}Lag of MapOSMatic OSM database: unknown.{% endblocktrans %}</p>
|
||||
<p class="error">{% blocktrans %}Could not connect to OSM database!{% endblocktrans %}</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue