【问题标题】:How to use AND operation in Riemann黎曼中如何使用AND运算
【发布时间】:2016-12-14 03:02:51
【问题描述】:

当两个条件都满足时,我有黎曼代码来触发电子邮件。所以我写了下面的代码。

(let [email (mailer {....email configuration})]
        (streams
    (where (service "log")
        (smap
          (fn [events]
           (let [count-of-failures (count (filter #(= "failed" (:Status %)) events) and (filter #(= "UK" (:Country %)) events))] ;Calculate the count for matched value
              (event
              {
                 :status "Failure"
                 :metric  count-of-failures 
                 :total-fail (>= count-of-failures 2)})))

          (where (and (= (:status event) "Failure")
                      (:total-fail event))


            (email "xxx@xx.com")
             )prn))))

一旦我开始执行clojure.lang.ArityException: Wrong number of args (3) passed to:,我就会遇到错误

任何人都可以在这里建议我使用AND操作的正确方法。

提前致谢

【问题讨论】:

    标签: clojure clojurescript riemann


    【解决方案1】:

    你给count 3 个参数 - 因此你得到错误。

    为什么你会在基本信息... args (3) passed to: count 无法理解之前截断错误输出。

    (let [email (mailer {....email configuration})]
      (streams
       (where (service "log")
              (smap
               (fn [events]
                 (let [count-of-failures (count ; <--- count only takes one argument
                                          (filter #(= "failed" (:Status %)) events)
                                          and
                                          (filter #(= "UK" (:Country %)) events))] ;Calculate the count for matched value
                   (event
                    {:status "Failure"
                     :metric  count-of-failures
                     :total-fail (>= count-of-failures 2)})))
    
               (where (and (= (:status event) "Failure")
                           (:total-fail event))
                      (email "xxx@xx.com")) prn))))
    

    从你的描述看不清楚,你的意思是:

    (count (and (filter ...) (filter ...)) 
    

    last not-nil 集合的计数是多少?


    我想检查两个条件我的 Status 应该是 Failed 和我的国家应该是 UK 。如果那时应该触发一封电子邮件

    这有帮助吗? :

    (def event {:Status "failed" :Country "UK"}) ; example1
    (some #(and (= "failed" (:Status %)) (= (:Country %) "UK")) [event])
    ; => true
    (def event {:Status "failed" :Country "US"}) ; example2
    (some #(and (= "failed" (:Status %)) (= (:Country %) "UK")) [event])
    ; => nil
    

    【讨论】:

    • (let [count-of-failures (count (filter #(= "failed" (:Status %)) events)) and (count (filter #(= "UK" (:Country %)) events))] 。这种方法行得通吗?
    • 我想检查两个条件,我的 Status 应该是 Failed 和我的 country 应该是 UK 。如果那时应该触发一封电子邮件
    猜你喜欢
    • 2017-02-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-23
    • 1970-01-01
    • 2019-10-24
    • 1970-01-01
    相关资源
    最近更新 更多