Commit 2f2541d2 authored by Alok Saldanha's avatar Alok Saldanha
Browse files

#6 added info output of env

improved logging config
parent d3a290a3
......@@ -8,6 +8,7 @@
# the specific language governing permissions and limitations under the License.
import os
import logging
cellxgene_location = os.environ.get("CELLXGENE_LOCATION")
cellxgene_data = os.environ.get("CELLXGENE_DATA")
......@@ -26,6 +27,11 @@ env_vars = {
"GATEWAY_IP": ip,
}
optional_env_vars = {
"GATEWAY_EXTRA_SCRIPTS": extra_scripts,
"GATEWAY_TTL": ttl,
"GATEWAY_ENABLE_UPLOAD": enable_upload,
}
def validate():
if not all(env_vars.values()):
......@@ -46,3 +52,6 @@ def validate():
export GATEWAY_IP=127.0.0.1
"""
)
else:
logging.getLogger("cellxgene_gateway").info(f"Got required env: {env_vars}", )
logging.getLogger("cellxgene_gateway").info(f"Got optional env: {optional_env_vars}")
......@@ -10,6 +10,7 @@
# import BaseHTTPServer
import datetime
import os
import logging
from threading import Thread
from flask import (
......@@ -204,6 +205,7 @@ def do_relaunch(path):
def main():
logging.basicConfig(level=logging.INFO, format='%(asctime)s:%(name)s:%(levelname)s:%(message)s')
env.validate()
pruner = PruneProcessCache(cache)
background_thread = Thread(target=pruner)
......
......@@ -29,11 +29,12 @@ class PruneProcessCache:
cutoff = timestamp - self.expire_seconds
processes_to_delete = [p for p in self.cache.entry_list if p.timestamp < cutoff]
processes_to_keep = [p for p in self.cache.entry_list if not p.timestamp < cutoff]
logging.getLogger("werkzeug").debug(f"Cutoff {cutoff} = timestamp {timestamp} - expire seconds {self.expire_seconds} , keeping {processes_to_keep}")
logger = logging.getLogger("cellxgene_gateway")
logger.debug(f"Cutoff {cutoff} = timestamp {timestamp} - expire seconds {self.expire_seconds} , keeping {processes_to_keep}")
for process in processes_to_delete:
try:
logging.getLogger("werkzeug").info(f"pruning process {process.pid} ({process.dataset})")
logger.info(f"pruning process {process.pid} ({process.dataset})")
self.cache.prune(process)
except Exception:
logging.getLogger("werkzeug").exception("failed to prune process {process.pid} ({process.dataset})")
logger.exception("failed to prune process {process.pid} ({process.dataset})")
......@@ -38,7 +38,7 @@ class SubprocessBackend:
cmd = self.create_cmd(
cellxgene_loc, cache_entry.file_path, cache_entry.port, scripts
)
logging.getLogger("werkzeug").info(f"launching {cmd}")
logging.getLogger("cellxgene_gateway").info(f"launching {cmd}")
process = subprocess.Popen(
[cmd], stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True
)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment