Ejemplo n.º 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()
Ejemplo n.º 2
0
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
Ejemplo n.º 3
0
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()