2016-08-08 3 views
0

両方の条件が満たされたときに電子メールをトリガーするリーマンコードがあります。だから私は以下のコードを書いた。リーマンでのAND演算の使い方

(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 "[email protected]") 
      )prn)))) 

私はclojure.lang.ArityException: Wrong number of args (3) passed to:

誰かが私にここで使用して、操作する正しい方法を提案してくださいすることができを実行し始めたら、私はエラーの下に取得しています。事前

答えて

0

おかげで、あなたは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 "[email protected]")) prn)))) 

それはあなたの説明から明らかではない、あなたは何をする意味した:最後ない-nilのコレクションをカウント

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

を?


私は私のステータスが障害されなければならないと私の国は英国であるべき2つの条件を確認したいです。その場合、電子メールがトリガーされるべきである場合

これは役に立ちますか? :

(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 
+0

'(みましょう[カウント・オブ・障害( (フィルター#(=( "失敗" カウント:ステータス%))のイベント)) と (カウント(フィルタ#(= "英国の"( – Mangoski

+0

「状態」が「失敗」、私の「国」が「英国」の2つの状態を確認したい場合は、電子メールがトリガーされるはずです。 – Mangoski

関連する問題