Commit c03cf355 authored by Floreal Cabanettes's avatar Floreal Cabanettes
Browse files

Add debug mode in app.props and log in this file when enabled for local scheduler

parent 07c77e9f
......@@ -11,6 +11,10 @@ web_url = http://localhost:5000
# Max size of uploaded files (also for files from URL):
max_upload_size = 3G # Please set the unit: M for Megabyte or G for Gigabyte (-1 without unit to don't set a limit)
# Debug (enable only for tests):
debug = False
log_dir = ###PROGRAM###/logs
[cluster]
drmaa_lib_path = ###SET_IT###
......@@ -60,4 +64,5 @@ menage_freq = 1
[jobs]
# Number of parallel runs for local jobs:
run_local = 1
data_prepare = 2
max_concurrent_dl = 5
......@@ -7,6 +7,7 @@ import psutil
import atexit
from datetime import datetime
from tendo import singleton
import argparse
# Allow only one instance:
me = singleton.SingleInstance()
......@@ -34,12 +35,18 @@ if config_reader.drmaa_lib_path is not None:
NB_RUN = config_reader.local_nb_runs
NB_PREPARE = config_reader.nb_data_prepare
DEBUG=True
DEBUG = config_reader.debug
LOG_FILE = "stdout"
def _printer(*messages):
if DEBUG:
print(*messages)
if LOG_FILE == "stdout":
print(*messages)
else:
with open(LOG_FILE, "a") as log_f:
print(*messages, file=log_f)
def start_job(id_job, batch_system_type="local"):
......@@ -177,7 +184,36 @@ def cleaner():
DRMAA_SESSION.exit()
def parse_args():
global DEBUG, LOG_FILE
parser = argparse.ArgumentParser(description="Start local scheduler")
parser.add_argument('-d', '--debug', type=str, required=False, help="File describing input files")
parser.add_argument('-l', '--log-dir', type=str, required=False, help="Url of the server")
args = parser.parse_args()
if args.debug is not None:
if args.debug.lower() == "true" or args.debug.lower == "1":
DEBUG = True
elif args.debug.lower() == "false" or args.debug.lower == "0":
DEBUG = False
else:
raise Exception("Invalid value for debug: %s (valid values: True, False)" % args.debug)
if args.log_dir is not None:
log_dir = args.log_dir
else:
log_dir = config_reader.log_dir
if DEBUG:
if log_dir == "stdout":
LOG_FILE = "stdout"
else:
LOG_FILE = os.path.join(config_reader.log_dir, "local_scheduler.log")
if __name__ == '__main__':
parse_args()
while True:
_printer("Check uploads...")
......
......@@ -80,6 +80,19 @@ class AppConfigReader:
except NoOptionError:
return -1
def get_debug(self):
try:
return self.reader.get("global", "debug").lower() == "true"
except NoOptionError:
return False
def get_log_dir(self):
try:
return self.replace_vars(self.reader.get("global", "log_dir"))
except NoOptionError:
if self.get_debug():
raise Exception("No log dir defined and debug=True")
def get_minimap2_exec(self):
try:
entry = self.reader.get("softwares", "minimap2")
......@@ -160,6 +173,12 @@ class AppConfigReader:
except (NoOptionError, NoSectionError):
return 2
def get_max_concurrent_dl(self):
try:
return int(self.reader.get("jobs", "max_concurrent_dl"))
except (NoOptionError, NoSectionError):
return 5
def get_drmaa_lib_path(self):
try:
return self.reader.get("cluster", "drmaa_lib_path")
......@@ -207,9 +226,3 @@ class AppConfigReader:
return min_size
except (NoOptionError, NoSectionError):
return 0
def get_max_concurrent_dl(self):
try:
return int(self.reader.get("jobs", "max_concurrent_dl"))
except (NoOptionError, NoSectionError):
return 5
......@@ -47,6 +47,9 @@ mailer = Mailer(app)
# Folder containing data:
app_data = config_reader.app_data
if config_reader.debug and config_reader.log_dir != "stdout" and not os.path.exists(config_reader.log_dir):
os.makedirs(config_reader.log_dir)
# Crons:
if os.getenv('DISABLE_CRONS') != "True":
print("Starting crons...")
......
Supports Markdown
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