Exemplo n.º 1
0
 def get_budget_callback(self, order, price, user_id):
     logger.info("%s Sending %d€ for as getBudgetResponse"%(user_id, price,))
     self.client.service.getBudgetResponse(
         order,
         price,
         self.get_auth(user_id),
     )
Exemplo n.º 2
0
def verify_and_finalize_order(order_id):
    session = sessionmaker(bind=engine)()
    order = session.query(Order).filter_by(id=order_id).one()
    if order.has_all_data():
        # We have all the info we need to choose the best pair
        best_sum = 999999999

        for manufacturer in manufacturers.iterkeys():
            for carrier in carriers.iterkeys():
                budget_man = getattr(order, "budget_%s"%(manufacturer,))
                budget_car = getattr(order, "budget_%s"%(carrier,))

                distance = getattr(order, "distance_%s"%(manufacturer,))
                distance_footprint = ((distance*0.001)*0.26)/1000

                actual = sum([budget_man, budget_car, distance_footprint])
                if actual < best_sum:
                    best_sum = actual
                    best_manufacturer = manufacturer
                    best_carrier = carrier

        logger.info("Backoffice decided best pair: %s and %s. Lets notify both."%(
            best_manufacturer, best_carrier,
        ))
        Notificator(order_id).notificate_all(best_manufacturer, best_carrier)
Exemplo n.º 3
0
def verify_and_finalize_order(order_id):
    session = sessionmaker(bind=engine)()
    order = session.query(Order).filter_by(id=order_id).one()
    if order.has_all_data():
        # We have all the info we need to choose the best pair
        best_sum = 999999999

        for manufacturer in manufacturers.iterkeys():
            for carrier in carriers.iterkeys():
                budget_man = getattr(order, "budget_%s" % (manufacturer, ))
                budget_car = getattr(order, "budget_%s" % (carrier, ))

                distance = getattr(order, "distance_%s" % (manufacturer, ))
                distance_footprint = ((distance * 0.001) * 0.26) / 1000

                actual = sum([budget_man, budget_car, distance_footprint])
                if actual < best_sum:
                    best_sum = actual
                    best_manufacturer = manufacturer
                    best_carrier = carrier

        logger.info(
            "Backoffice decided best pair: %s and %s. Lets notify both." % (
                best_manufacturer,
                best_carrier,
            ))
        Notificator(order_id).notificate_all(best_manufacturer, best_carrier)
Exemplo n.º 4
0
 def getBudget(self, order, name, address, auth):
     if is_valid_request(auth):
         thread.start_new_thread(
             calculate_budget_price,
             (order, name, address, self.user_id,)
         )
         logger.info("%s Returning async request for getBudget"%(self.user_id,))
         return "OK"
Exemplo n.º 5
0
 def confirmBudget(self, order, auth):
     if is_valid_request(auth):
         thread.start_new_thread(
             set_status_order,
             (order, self.user_id,)
         )
         logger.info("%s Returning sync request for confirmBudget"%(self.user_id,))
         return "OK"
Exemplo n.º 6
0
 def changeStatusOrder(self, order_id, status):
     logger.info(
         "Backoffice informing frontend that order %d status changed to %s"%(
             order_id,
             status,
         )
     )
     self.client.service.changeStatusOrder(order_id, status)
Exemplo n.º 7
0
 def confirmBudget(self, order, auth):
     if is_valid_request(auth):
         thread.start_new_thread(set_status_order, (
             order,
             self.user_id,
         ))
         logger.info("%s Returning sync request for confirmBudget" %
                     (self.user_id, ))
         return "OK"
Exemplo n.º 8
0
 def get_budget_callback(self, order, price, user_id):
     logger.info("%s Sending %d€ for as getBudgetResponse" % (
         user_id,
         price,
     ))
     self.client.service.getBudgetResponse(
         order,
         price,
         self.get_auth(user_id),
     )
Exemplo n.º 9
0
 def getBudget(self, order, tracks, auth):
     if is_valid_request(auth):
         thread.start_new_thread(calculate_budget_price, (
             order,
             tracks,
             self.user_id,
         ))
         logger.info("%s Returning async request for getBudget" %
                     (self.user_id, ))
         return "OK"
Exemplo n.º 10
0
    def set_status_order(self, order, status, user_id):
        logger.info("%s Sending %s as status for order number %d" % (
            user_id,
            status,
            order,
        ))

        self.client.service.setStatusOrder(
            order,
            status,
            self.get_auth(user_id),
        )
Exemplo n.º 11
0
    def set_status_order(self, order, status, user_id):
        logger.info("%s Sending %s as status for order number %d"%(
            user_id,
            status,
            order,)
        )

        self.client.service.setStatusOrder(
            order,
            status,
            self.get_auth(user_id),
        )
Exemplo n.º 12
0
    def submitOrder(self, order, auth):
        if is_valid_request(auth):
            # persist the new order
            processor = OrderProcessor()
            new_order = processor.create_order(order.name, order.address)

            # create thread and process order
            thread.start_new_thread(processor.process_order, (order.tracks,))

            # return the order unique id
            logger.info("Backoffice: Returning async request for submit order")
            return new_order.id
Exemplo n.º 13
0
    def submitOrder(self, order, auth):
        if is_valid_request(auth):
            #persist the new order
            processor = OrderProcessor()
            new_order = processor.create_order(order.name, order.address)

            #create thread and process order
            thread.start_new_thread(
                processor.process_order,
                (order.tracks, ),
            )

            #return the order unique id
            logger.info("Backoffice: Returning async request for submit order")
            return new_order.id
Exemplo n.º 14
0
            # create thread and process order
            thread.start_new_thread(processor.process_order, (order.tracks,))

            # return the order unique id
            logger.info("Backoffice: Returning async request for submit order")
            return new_order.id

    @soap(Integer, Integer, Auth, _returns=String)
    def getBudgetResponse(self, order, price, auth):
        if is_valid_request(auth):
            create_budget(auth.user_id, order, price)
            verify_and_finalize_order(order)

    @soap(Integer, String, Auth, _returns=String)
    def setStatusOrder(self, order, status, auth):
        if is_valid_request(auth):
            Notificator(order).notificate_frontend(status)
            return "OK"


if __name__ == "__main__":
    host = sys.argv[1]
    port = int(sys.argv[2])

    soap_application = Application([MusicService, OrderService], "tns")
    wsgi_application = wsgi.Application(soap_application)
    server = make_server(host, port, wsgi_application)
    logger.info("Backoffice serving on %s:%s" % (host, port))
    server.serve_forever()
Exemplo n.º 15
0
            thread.start_new_thread(set_status_order, (
                order,
                self.user_id,
            ))
            logger.info("%s Returning sync request for confirmBudget" %
                        (self.user_id, ))
            return "OK"


if __name__ == "__main__":
    host = sys.argv[1]
    port = int(sys.argv[2])
    user_id_dict = {
        '7888': 'manufacturerA',
        '7889': 'manufacturerB',
        '7890': 'manufacturerC',
    }

    class BudgetApplication(Application):
        def get_service(self, service, *args, **kwargs):
            return service(user_id_dict.get(str(port)))

    soap_application = BudgetApplication([BudgetService], 'tns')
    wsgi_application = wsgi.Application(soap_application)
    server = make_server(host, port, wsgi_application)
    logger.info("Manufacturer serving on %s:%s" % (
        host,
        port,
    ))
    server.serve_forever()
Exemplo n.º 16
0
 def confirmBudget(self, order_id):
     logger.info("Backoffice confirming %s budget"%(self.endpoint,))
     self.client.service.confirmBudget(order_id, self.get_auth_instance())
Exemplo n.º 17
0
 def getBudget(self, order, name, address):
     logger.info("Backoffice asking %s for a budget"%(self.endpoint,))
     self.client.service.getBudget(order, name, address, self.get_auth_instance())
Exemplo n.º 18
0
 def getTracks(self, artist_name, auth):
     if is_valid_request(auth):
         response = LastFMClient().getArtistTracks(unquote(artist_name))
         logger.info("Backoffice: Returning request for tracks search")
         return response
Exemplo n.º 19
0
            #return the order unique id
            logger.info("Backoffice: Returning async request for submit order")
            return new_order.id

    @soap(Integer, Integer, Auth, _returns=String)
    def getBudgetResponse(self, order, price, auth):
        if is_valid_request(auth):
            create_budget(auth.user_id, order, price)
            verify_and_finalize_order(order)

    @soap(Integer, String, Auth, _returns=String)
    def setStatusOrder(self, order, status, auth):
        if is_valid_request(auth):
            Notificator(order).notificate_frontend(status)
            return "OK"


if __name__ == "__main__":
    host = sys.argv[1]
    port = int(sys.argv[2])

    soap_application = Application([MusicService, OrderService], 'tns')
    wsgi_application = wsgi.Application(soap_application)
    server = make_server(host, port, wsgi_application)
    logger.info("Backoffice serving on %s:%s" % (
        host,
        port,
    ))
    server.serve_forever()
Exemplo n.º 20
0
    @soap(Integer, Auth, _returns=String)
    def confirmBudget(self, order, auth):
        if is_valid_request(auth):
            thread.start_new_thread(
                set_status_order,
                (order, self.user_id,)
            )
            logger.info("%s Returning sync request for confirmBudget"%(self.user_id,))
            return "OK"


if __name__=="__main__":
    host = sys.argv[1]
    port = int(sys.argv[2])
    user_id_dict={
        '7888':'manufacturerA',
        '7889':'manufacturerB',
        '7890':'manufacturerC',
    }

    class BudgetApplication(Application):
        def get_service(self, service, *args, **kwargs):
            return service(user_id_dict.get(str(port)))

    soap_application = BudgetApplication([BudgetService], 'tns')
    wsgi_application = wsgi.Application(soap_application)
    server = make_server(host, port, wsgi_application)
    logger.info("Manufacturer serving on %s:%s"%(host,port,))
    server.serve_forever()
Exemplo n.º 21
0
 def getTracks(self, artist_name, auth):
     if is_valid_request(auth):
         response = LastFMClient().getArtistTracks(unquote(artist_name))
         logger.info("Backoffice: Returning request for tracks search")
         return response
Exemplo n.º 22
0
            return "OK"

    @soap(Integer, Auth, _returns=String)
    def confirmBudget(self, order, auth):
        if is_valid_request(auth):
            thread.start_new_thread(
                set_status_order,
                (order, self.user_id,)
            )
            logger.info("%s Returning sync request for confirmBudget"%(self.user_id,))
            return "OK"

if __name__=="__main__":
    host = sys.argv[1]
    port = int(sys.argv[2])
    user_id_dict={
        '7885':'carrierA',
        '7886':'carrierB',
        '7887':'carrierC',
    }

    class BudgetApplication(Application):
        def get_service(self, service, *args, **kwargs):
            return service(user_id_dict.get(str(port)))

    soap_application = BudgetApplication([BudgetService], 'tns')
    wsgi_application = wsgi.Application(soap_application)
    server = make_server(host, port, wsgi_application)
    logger.info("Carrier serving on %s:%s"%(host,port,))
    server.serve_forever()
Exemplo n.º 23
0
            thread.start_new_thread(set_status_order, (
                order,
                self.user_id,
            ))
            logger.info("%s Returning sync request for confirmBudget" %
                        (self.user_id, ))
            return "OK"


if __name__ == "__main__":
    host = sys.argv[1]
    port = int(sys.argv[2])
    user_id_dict = {
        '7885': 'carrierA',
        '7886': 'carrierB',
        '7887': 'carrierC',
    }

    class BudgetApplication(Application):
        def get_service(self, service, *args, **kwargs):
            return service(user_id_dict.get(str(port)))

    soap_application = BudgetApplication([BudgetService], 'tns')
    wsgi_application = wsgi.Application(soap_application)
    server = make_server(host, port, wsgi_application)
    logger.info("Carrier serving on %s:%s" % (
        host,
        port,
    ))
    server.serve_forever()