Esempio n. 1
0
def main():
    parser = argparse.ArgumentParser(description='Run LOST cronjobs')
    parser.add_argument('--debug',
                        action='store_true',
                        help='start cronjobs just once for debugging')
    args = parser.parse_args()
    lostconfig = config.LOSTConfig()
    fm = AppFileMan(lostconfig)
    log_name = 'cron_jobs'
    logger = get_file_logger(log_name, fm.get_app_log_path('cron_jobs.log'))
    logger.info('Starting cron jobs!')
    if args.debug:
        t = threading.Thread(target=worker_lifesign_loop,
                             args=(log_name, ),
                             daemon=True)
        t.start()
        client = Client('{}:{}'.format(lostconfig.scheduler_ip,
                                       lostconfig.scheduler_port))
        process_pipes(log_name, client)
    else:
        jobs = [
            process_pipes_loop, worker_lifesign_loop, release_annos_loop,
            remove_empty_annos_loop
        ]
        if lostconfig.worker_management == 'dynamic':
            jobs.append(dask_session.release_client_by_timeout_loop)
        jobs += lostconfig.extra_cron_jobs
        threads = []
        for j in jobs:
            t = threading.Thread(target=j, args=(log_name, ), daemon=True)
            t.start()
            threads.append(t)
        [t.join() for t in threads]
Esempio n. 2
0
from flask import Flask
from lost import settings
# from lost.taskman import make_celery
from lost.logic.file_man import AppFileMan
from flask_mail import Mail
import os
import traceback

app = Flask(__name__)

import logging
from logging import FileHandler

file_man = AppFileMan(settings.LOST_CONFIG)
logfile_path = file_man.get_app_log_path('flask.log')
# log_file_stream = file_man.fs.open(logfile_path, 'a')
# file_handler = StreamHandler(log_file_stream)
file_handler = FileHandler(logfile_path)
if settings.LOST_CONFIG.debug:
    logging.basicConfig(level=logging.INFO)
    file_handler.setLevel(logging.INFO)
else:
    file_handler.setLevel(logging.WARNING)
formatter = logging.Formatter(
    "%(asctime)s - %(name)s - %(levelname)s - %(message)s")
file_handler.setFormatter(formatter)
app.logger.addHandler(file_handler)

# app.config['CELERY_BROKER_URL'] = settings.CELERY_BROKER_URL
# app.config['CELERY_RESULT_BACKEND'] = settings.CELERY_RESULT_BACKEND