import uuid import logging import tornado.web import os import sys from tornado.util import ObjectDict from tornado.escape import json_decode, json_encode from sqlalchemy.orm import defer from sqlalchemy import literal_column, desc, column from app.config import DBSession from app.config import CONF from app.model import User, Session, ActionLog from util import UtilHandler COOKIE_NAME = CONF.get('general', 'cookie_name') DEBUG = CONF.getboolean('general', 'debug') logger = logging.getLogger('app.base') class BaseHandler(tornado.web.RequestHandler, UtilHandler): SUPPORTED_METHODS = ('GET', 'POST') @property def session(self): if not hasattr(self, '_session'): self._session = DBSession return self._session def on_finish(self): if hasattr(self, '_session'):
self.session.query(Sms).filter_by(id=s.id).update( { 'status': Sms.STATUS_COMPLETE, 'last': now }, synchronize_session=False) else: self.session.query(Sms).filter_by(id=s.id).update( {'last': now}, synchronize_session=False) self.session.commit() def run(self): logger.info('turn') self.session.commit() self.session.query('1').all() try: self.fail() self.do() except: logger.error('ERROR', exc_info=True) IOLoop().current().add_timeout( IOLoop().current().time() + random.randint(5, 10), self.run) self.session.commit() if __name__ == '__main__': Timer().run() if CONF.getboolean('log:filelog', 'enable'): LocalLog.start() IOLoop().current().start()