Initial commit

This commit is contained in:
Marcus Lindvall 2017-10-18 16:35:10 +02:00
commit 351d98c523
36 changed files with 1836 additions and 0 deletions

71
pyjeeves/main.py Normal file
View file

@ -0,0 +1,71 @@
# -*- coding: utf-8 -*-
import pprint
import yaml
import signal
import sys
import logging
import logging.config
from alembic.config import Config
from alembic import command
from process import Process
from jvsquery import JvsQuery
from db import MySQLSession
from utils import TaskThread
pp = pprint.PrettyPrinter(indent=4)
class SyncTread(TaskThread):
"""docstring for ClassName"""
def __init__(self, config):
super(SyncTread, self).__init__()
jvs_query = JvsQuery(config['jeeves_db'])
db_session = MySQLSession(config['mysql'])
self.process = Process(jvs_query, db_session)
self.logger = logging.getLogger("PyJeeves.SyncTread")
def task(self):
self.logger.info("Started sync")
self.process.sync_data()
self.logger.info("Finished sync")
if __name__ == '__main__':
with open("config.yml", 'r') as ymlfile:
cfg = yaml.load(ymlfile)
logging.config.dictConfig(cfg['logging'])
logger = logging.getLogger("PyJeeves")
logger.info("Running migrations")
alembic_cfg = Config()
for k in cfg['alembic']:
alembic_cfg.set_main_option(k, cfg['alembic'][k])
command.upgrade(alembic_cfg, "head")
logger.info("Application started")
def sigterm_handler(signal, frame):
# save the state here or do whatever you want
logger.info('Application interrupted')
sys.exit(0)
signal.signal(signal.SIGINT, sigterm_handler)
signal.signal(signal.SIGTERM, sigterm_handler)
sync_thread = SyncTread(cfg)
try:
sync_thread.setInterval(cfg['sync_interval'])
sync_thread.start()
sync_thread.join()
finally:
sync_thread.shutdown()
logger.info("Thread stopped")
logger.info("Application stopped")