Skip to content

Commit

Permalink
loglevel, systems, exitfix
Browse files Browse the repository at this point in the history
- allow to set loglevel with env variable (LOGLEVEL)
- systems.json contains systems to check
- unregister when exit
  • Loading branch information
robkooper committed Aug 2, 2024
1 parent 0253b4c commit 6909c45
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ docker-compose.override.yml

*.pyc
*.DS_Store
[Ll]ogs
[Ll]ogs
data
1 change: 1 addition & 0 deletions cdrhook/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ ENV PYTHONUNBUFFERED=1 \
CALLBACK_USERNAME="" \
CALLBACK_PASSWORD="" \
RABBITMQ_URI="amqp://guest:guest@localhost:5672/%2F" \
LOGLEVEL="INFO" \
PREFIX=""

VOLUME /data
Expand Down
13 changes: 8 additions & 5 deletions cdrhook/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ def process_cog(cdr_connector : CdrConnector , cog_id : str, config_parm : Optio
"""
if config_parm is None:
config_parm = config
valid_area_systems = ['uncharted-area']
valid_legend_systems = ['polymer', 'uncharted-area']
valid_area_systems = config_parm["systems"]["area"]
valid_legend_systems = config_parm["systems"]["legend"]

logging.info(f"Cog:{cog_id[0:8]} - Processing cog {cog_id}")
# Retrieve available system versions for this cog and check if there are any valid systems posted
Expand All @@ -184,7 +184,7 @@ def process_cog(cdr_connector : CdrConnector , cog_id : str, config_parm : Optio

if not valid_systems:
# logging.error(f"{cog_id[0:8]} - No valid system data found on CDR")
raise ValueError(f"No valid system data found on CDR for {cog_id}")
raise ValueError(f"No valid system data found on CDR for {cog_id}, only saw {cog_system_versions.pretty_str()}")
# return
else:
logging.debug(f"Cog-{cog_id[0:8]} - Available system versions : {cog_system_versions.pretty_str()}")
Expand Down Expand Up @@ -422,6 +422,8 @@ def create_app():
# load the models
with open("models.json", "r") as f:
config["models"] = json.load(f)
with open("systems.json", "r") as f:
config["systems"] = json.load(f)

# register with the CDR
cdr_connector = CdrConnector(
Expand Down Expand Up @@ -457,10 +459,11 @@ def create_app():
if __name__ == '__main__':
logging.basicConfig(format='%(asctime)-15s [%(threadName)-15s] %(levelname)-7s :'
' %(name)s - %(message)s',
level=logging.DEBUG)
level=logging.getLevelName(os.getenv("LOGLEVEL", "INFO").upper()))
logging.getLogger('requests.packages.urllib3.connectionpool').setLevel(logging.WARN)
logging.getLogger('urllib3.connectionpool').setLevel(logging.WARN)
logging.getLogger('pika').setLevel(logging.WARN)
logging.info("Starting up with loglevel %s", os.getenv("LOGLEVEL", "INFO"))

app = create_app()
server = create_server(app, host="0.0.0.0", port=8080)
Expand All @@ -469,7 +472,7 @@ def create_app():
# this does not work.
def handle_sig(sig, frame):
logging.warning(f"Got signal {sig}, now close worker...")
cdr_connector.unregister()
config["cdr_connector"].unregister()
sys.exit(0)

for sig in (signal.SIGINT, signal.SIGTERM, signal.SIGQUIT, signal.SIGHUP):
Expand Down
4 changes: 4 additions & 0 deletions cdrhook/systems.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"area": ["uncharted"],
"legend": ["polymer", "uncharted-area"]
}

0 comments on commit 6909c45

Please sign in to comment.