Commit 8d2ed74a authored by Michael Salim's avatar Michael Salim
Browse files

logging

parent 36b52c8a
......@@ -12,7 +12,7 @@ https://docs.djangoproject.com/en/1.9/ref/settings/
import os
import sys
from balsam.django_config import serverinfo, sqlite_client
from balsam.django_config import serverinfo
from balsam.user_settings import *
# ---------------
......@@ -55,19 +55,6 @@ CONCURRENCY_ENABLED = True
BALSAM_PATH = resolve_db_path()
DATABASES = configure_db_backend(BALSAM_PATH)
# -----------------------
# SQLITE CLIENT SETUP
# ------------------------
is_server = os.environ.get('IS_BALSAM_SERVER')=='True'
is_daemon = os.environ.get('IS_SERVER_DAEMON')=='True'
using_sqlite = DATABASES['default']['ENGINE'].endswith('sqlite3')
SAVE_CLIENT = None
if using_sqlite and not (is_server or is_daemon):
SAVE_CLIENT = sqlite_client.Client(serverinfo.ServerInfo(BALSAM_PATH))
if SAVE_CLIENT.serverAddr is None:
SAVE_CLIENT = None
# --------------------
# SUBDIRECTORY SETUP
# --------------------
......@@ -145,6 +132,20 @@ def log_uncaught_exceptions(exctype, value, tb,logger=logger):
logger.error(f"Uncaught Exception {exctype}: {value}",exc_info=(exctype,value,tb))
sys.excepthook = log_uncaught_exceptions
# -----------------------
# SQLITE CLIENT SETUP
# ------------------------
is_server = os.environ.get('IS_BALSAM_SERVER')=='True'
is_daemon = os.environ.get('IS_SERVER_DAEMON')=='True'
using_sqlite = DATABASES['default']['ENGINE'].endswith('sqlite3')
SAVE_CLIENT = None
if using_sqlite and not (is_server or is_daemon):
from balsam.django_config import sqlite_client
SAVE_CLIENT = sqlite_client.Client(serverinfo.ServerInfo(BALSAM_PATH))
if SAVE_CLIENT.serverAddr is None:
SAVE_CLIENT = None
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '=gyp#o9ac0@w3&-^@a)j&f#_n-o=k%z2=g5u@z5+klmh_*hebj'
......
......@@ -2,7 +2,6 @@ from io import StringIO
from traceback import print_exc
import json
import os
import logging
import zmq
from django.db.utils import OperationalError
......@@ -13,6 +12,7 @@ REQ_RETRY = 3
class Client:
def __init__(self, server_info):
import logging
self.logger = logging.getLogger(__name__)
self.server_info = server_info
self.serverAddr = self.server_info.get('address')
......@@ -40,7 +40,10 @@ class Client:
if socks.get(client) == zmq.POLLIN:
reply = client.recv()
client.close()
poll.unregister(client)
context.term()
self.logger.debug(f"received reply: {reply}")
return reply.decode('utf-8')
else:
self.logger.debug("No response from server, retrying...")
......
......@@ -18,7 +18,6 @@ from balsam.service.models import BalsamJob
from balsam.django_config import serverinfo
logger = logging.getLogger('balsam.django_config.sqlite_server')
logger.info("HERE IS SERVER!")
SERVER_PERIOD = 1000
TERM_LINGER = 20 # if SIGTERM, wait 20 sec after final save() to exit
......@@ -42,12 +41,14 @@ class ZMQServer:
events = self.socket.poll(timeout=SERVER_PERIOD)
if events:
message = self.socket.recv().decode('utf-8')
logger.debug(f'request: {message}')
else:
message = None
return message
def send_reply(self, msg):
self.socket.send_string(msg)
logger.debug(f"Sent reply {msg}")
def save(self, job_msg):
d = json.loads(job_msg)
......@@ -77,15 +78,18 @@ def server_main(db_path):
while not terminate or time.time() - last_save_time < TERM_LINGER:
message = server.recv_request()
logger.debug(f"received message: {message}")
if message is None:
if os.getppid() != parent_pid:
logger.info("detected parent died; server quitting")
break
elif 'job_id' in message:
logger.debug("sending ACK_SAVE?")
last_save_time = server.save(message)
server.send_reply("ACK_SAVE")
else:
logger.debug("sending ACK")
server.send_reply("ACK")
if __name__ == "__main__":
......
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