71 lines
1.8 KiB
Python
71 lines
1.8 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
import pprint
|
|
import signal
|
|
import sys
|
|
|
|
# import logging
|
|
# import logging.config
|
|
|
|
from alembic.config import Config
|
|
from alembic import command
|
|
|
|
from pyjeeves.connector import DBConnector
|
|
from pyjeeves import config
|
|
from process import Process
|
|
from jvsquery import JvsQuery
|
|
from utils import TaskThread
|
|
|
|
|
|
pp = pprint.PrettyPrinter(indent=4)
|
|
|
|
|
|
class SyncTread(TaskThread):
|
|
"""docstring for ClassName"""
|
|
def __init__(self, config):
|
|
super(SyncTread, self).__init__()
|
|
|
|
# Use RawSession instead...
|
|
jvs_query = JvsQuery()
|
|
None, db_session = DBConnector.create_scoped_session(['meta'])
|
|
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__':
|
|
|
|
from pyjeeves import logging
|
|
# logging.config.dictConfig(config['logging'])
|
|
logger = logging.getLogger("PyJeeves")
|
|
|
|
logger.info("Running migrations")
|
|
alembic_cfg = Config()
|
|
for k in config['alembic']:
|
|
alembic_cfg.set_main_option(k, config['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()
|
|
try:
|
|
sync_thread.setInterval(config['sync_interval'])
|
|
sync_thread.start()
|
|
sync_thread.join()
|
|
finally:
|
|
sync_thread.shutdown()
|
|
logger.info("Thread stopped")
|
|
|
|
logger.info("Application stopped")
|