コード例 #1
0
        def callback(ch, method, properties, body):
            event = json.body_to_dic(body.decode('utf-8'))
            if (len(validator.validateSchema(EVENT_CALLBACK, event)) > 0):
                return

            if (event["type"] == "article-exist"):
                message = event["message"]
                if (len(validator.validateSchema(MSG_ARTICLE_EXIST, message)) >
                        0):
                    return

                exchange = event["exchange"]
                queue = event["queue"]
                referenceId = message["referenceId"]
                articleId = message["articleId"]

                print(
                    "RabbitMQ Catalog GET article-exist catalogId:%r , articleId:%r",
                    referenceId, articleId)

                try:
                    articleValidation.validateArticleExist(articleId)
                    sendArticleValid(exchange, queue, referenceId, articleId,
                                     True)
                except Exception:
                    sendArticleValid(exchange, queue, referenceId, articleId,
                                     False)

            if (event["type"] == "article-data"):
                message = event["message"]
                if (len(validator.validateSchema(MSG_ARTICLE_EXIST, message)) >
                        0):
                    return

                exchange = event["exchange"]
                queue = event["queue"]
                referenceId = message["referenceId"]
                articleId = message["articleId"]

                print(
                    "RabbitMQ Catalog GET article-data catalogId:%r , articleId:%r",
                    referenceId, articleId)

                try:
                    article = crud.getArticle(articleId)
                    valid = ("enabled" in article and article["enabled"])
                    stock = article["stock"]
                    price = article["price"]
                    articleValidation.validateArticleExist(articleId)
                    sendArticleData(exchange, queue, referenceId, articleId,
                                    valid, stock, price)
                except Exception:
                    sendArticleData(exchange, queue, referenceId, articleId,
                                    False, 0, 0)
コード例 #2
0
ファイル: route.py プロジェクト: enzo4chinuri/Category
 def getArticle(articleId):
     try:
         return json.dic_to_json(crud.getArticle(articleId))
     except Exception as err:
         return errors.handleError(err)
コード例 #3
0
def validateArticleExist(articleId):
    article = crud.getArticle(articleId)
    if ("enabled" not in article or not article["enabled"]):
        raise error.InvalidArgument("_id", "Inválido")