diff --git a/web/app/borders_daemon.py b/web/app/borders_daemon.py index bd991c9..f0d6c2a 100755 --- a/web/app/borders_daemon.py +++ b/web/app/borders_daemon.py @@ -25,7 +25,7 @@ CHECK_BORDERS_INTERVAL = 10 no_count_queries = [ f""" SELECT id, name - FROM + FROM ( SELECT id, name, ST_Area(geography(geom))/1000000.0 area, ST_Area(geography(ST_Envelope(geom)))/1000000.0 env_area @@ -45,7 +45,7 @@ class App(): self.stdin_path = '/dev/null' self.stdout_path = '/dev/tty' self.stderr_path = '/dev/tty' - self.pidfile_path = '/var/log/borders-daemon.pid' + self.pidfile_path = config.DAEMON_PID_PATH self.pidfile_timeout = 5 self.conn = None @@ -65,11 +65,10 @@ class App(): self.conn.close() except: pass - time.sleep(CONNECT_WAIT_INTERVAL) - + time.sleep(CONNECT_WAIT_INTERVAL) def process(self, region_id, region_name): - msg = f'Processing {region_name} ({region_id})' + msg = f'Processing {region_name} ({region_id})' logger.info(msg) try: f = open(config.DAEMON_STATUS_PATH, 'w') @@ -82,7 +81,7 @@ class App(): with self.get_connection().cursor() as cur: cur.execute(f""" UPDATE {table} - SET count_k = n.count + SET count_k = n.count FROM (SELECT coalesce(sum(t.count), 0) AS count FROM {table} b, tiles t WHERE b.id = %s AND ST_Intersects(b.geom, t.tile) @@ -121,7 +120,7 @@ def init_logger(): logger = logging.getLogger("borders-daemon") logger.setLevel(logging.INFO) formatter = logging.Formatter("%(asctime)s [%(levelname)s] %(message)s") - handler = logging.FileHandler("/var/log/borders-daemon.log") + handler = logging.FileHandler(config.DAEMON_LOG_PATH) #handler = logging.StreamHandler() handler.setFormatter(formatter) logger.addHandler(handler) diff --git a/web/app/config.py b/web/app/config.py index 13e5cec..7b8d2e2 100644 --- a/web/app/config.py +++ b/web/app/config.py @@ -3,7 +3,7 @@ CONNECTION = 'dbname=borders user=borders password=borders host=dbhost port=5432 # passed to flask.Debug DEBUG = True # if the main table is read-only -READONLY = False +READONLY = False # main table name TABLE = 'borders' # from where OSM borders are imported @@ -25,4 +25,6 @@ JOSM_FORCE_MULTI = True # alert instead of json on import error IMPORT_ERROR_ALERT = False # file to which daemon writes the name of currently processed region -DAEMON_STATUS_PATH = '/var/tmp/borders-daemon-status.txt' +DAEMON_STATUS_PATH = '/tmp/borders-daemon-status.txt' +DAEMON_PID_PATH = '/tmp/borders-daemon.pid' +DAEMON_LOG_PATH = '/var/log/borders-daemon.log'