예제 #1
0
    def run(self):
        """
            Sets up the application, runs the command, and then tears everything down
        """
        system.initialize()

        try:
            RemoteCommand.__LOGGER.debug("Starting remote command: %s", self.__command.command_key)
            AbstractDAO.begin()
            self.__command.run()
            AbstractDAO.commit()
            RemoteCommand.__LOGGER.debug("Finished remote command: %s", self.__command.command_key)
        except Exception:
            RemoteCommand.__LOGGER.exception("Error while running remote command: %s", self.__command.command_key)
            AbstractDAO.rollback()
        finally:
            system.dispose()
예제 #2
0
파일: server.py 프로젝트: sgiroux/trex
def initialize():
    """
        Initializes the application.
    """
    system.initialize(os.path.abspath(os.path.join(os.path.dirname(__file__), ".env")))

    api = falcon.API(
        media_type='application/json; charset=utf-8',
        middleware=[RequireJSON(), Cors(), Authentication(), DAOTransaction()]
    )
    api.add_error_handler(Exception, exceptions.handle_exception)

    # Add all your routes here
    api.add_route('/expenses', ExpenseHandler(authentication.API_TOKEN_HEADER_AUTHENTICATION_SERVICE))
    api.add_route('/expenses/{expense_id}', ExpenseIDHandler(authentication.API_TOKEN_HEADER_AUTHENTICATION_SERVICE))
    api.add_route('/user-settings/{user_setting_id}', UserSettingHandler(authentication.API_TOKEN_HEADER_AUTHENTICATION_SERVICE))


    # Non-API routes
    api.add_route('/user-summary', UserSummaryHandler(authentication.API_TOKEN_HEADER_AUTHENTICATION_SERVICE))
    api.add_route('/login', LoginHandler(authentication.ANONYMOUS_AUTHENTICATION_SERVICE))
    api.add_route('/register', RegisterHandler(authentication.ANONYMOUS_AUTHENTICATION_SERVICE))

    return api
예제 #3
0
파일: worker.py 프로젝트: sgiroux/trex
import os
from rq import Worker, Queue, Connection
from trex import system

system.initialize(os.path.abspath(os.path.join(os.path.dirname(__file__), ".env")))

if __name__ == '__main__':
    import argparse

    parser = argparse.ArgumentParser(description="Initializes a queue worker")
    parser.add_argument('queue', type=str, help="The queue you want this worker to process")
    args = parser.parse_args()

    with Connection(system.REDIS_CLIENT):
        queue = Queue(args.queue)
        worker = Worker(queue)
        worker.work()