gpt4 book ai didi

clojure.lang.LazySeq 不能转换为 clojure.lang.IFn

转载 作者:行者123 更新时间:2023-12-01 12:35:37 29 4
gpt4 key购买 nike

我是 Riemann 和 Clojure 的新手。我想要做的就是在某些服务的 TTL 到期时向三个电子邮件组发送电子邮件通知。
我创建了某种配置文件,用于存储电子邮件列表:

{
:email_group_1 (
"first@example.com"
"second@example.ru"
)
:email_group_2 (
"third@example.com"
)
}

我的 riemann 配置如下所示:
(logging/init {:console true})
(import org.apache.log4j.Level)
(logging/set-level Level/DEBUG)

(require '[clojure.java.io :as io])
(import '[java.io PushbackReader])

(let [host "0.0.0.0"]
(tcp-server {:host host :port 60001})
(udp-server {:host host})
(ws-server {:host host :port 60003}))
(repl-server {:host "127.0.0.1"})

(def cwd (System/getProperty "user.dir"))

(def emails
(with-open [r (io/reader (str cwd "/etc/emails.clj"))]
(read (PushbackReader. r))))

(periodically-expire 5)

(def email (mailer))

(defn notify [& egroups]
(for [egroup egroups]
(rollup 1 60 (apply email (emails egroup)))))

(let [index (index)]
(streams
(default :ttl 60
index

(expired
(where (service "service_connect_active")
#(info "expired" %)
(notify :email_group_1 :email_group_2))))))

代码看起来不错(对我来说),但是当此服务过期时,我收到以下错误:
09:45:39 riemann.1      | INFO [2015-05-08 10:45:39,313] Thread-5 - riemann.config - expired {:ttl 60, :time 357766884827/250, :state expired, :service service_connect_active, :host ava.local}
09:45:39 riemann.1 | WARN [2015-05-08 10:45:39,319] Thread-5 - riemann.config - clojure.lang.LazySeq@841649b8 threw
09:45:39 riemann.1 | java.lang.ClassCastException: clojure.lang.LazySeq cannot be cast to clojure.lang.IFn
09:45:39 riemann.1 | at riemann.config$eval66$stream__70$fn__75.invoke(riemann.development.config:34)
09:45:39 riemann.1 | at riemann.config$eval66$stream__70.invoke(riemann.development.config:45)
09:45:39 riemann.1 | at riemann.streams$match$stream__3514$fn__3525.invoke(streams.clj:1209)
09:45:39 riemann.1 | at riemann.streams$match$stream__3514.invoke(streams.clj:1209)
09:45:39 riemann.1 | at riemann.streams$default$stream__3731$fn__3742.invoke(streams.clj:1328)
09:45:39 riemann.1 | at riemann.streams$default$stream__3731.invoke(streams.clj:1328)
09:45:39 riemann.1 | at riemann.core$stream_BANG_$fn__4415.invoke(core.clj:19)
09:45:39 riemann.1 | at riemann.core$stream_BANG_.invoke(core.clj:18)
09:45:39 riemann.1 | at riemann.core$reaper$worker__4529$fn__4539.invoke(core.clj:303)
09:45:39 riemann.1 | at riemann.core$reaper$worker__4529.invoke(core.clj:297)
09:45:39 riemann.1 | at riemann.service.ThreadService$thread_service_runner__1973$fn__1974.invoke(service.clj:71)
09:45:39 riemann.1 | at riemann.service.ThreadService$thread_service_runner__1973.invoke(service.clj:70)
09:45:39 riemann.1 | at clojure.lang.AFn.run(AFn.java:22)
09:45:39 riemann.1 | at java.lang.Thread.run(Thread.java:745)

有人可以帮我吗?谢谢。

最佳答案

“cannot to be cast to clojure.lang.IFn”错误总是指向一些期望函数被赋予一些不能被视为这样的东西......

(defn notify [& egroups]
(for [egroup egroups]
(rollup 1 60 (apply email (emails egroup)))))

这将返回一个 for-generated LazySeq 的汇总流,而不是实际的流(在 Riemann 中,流是一个 IFn)。因此,当 Riemann 尝试将流作为 IFn 调用时,您的错误就会发生......

怎么样:
(defn notify [& egroups]
(rollup 1 60 (apply email (mapcat emails egroups))))

在这里,我们只是预先将群组列表转换为电子邮件列表,然后继续我们的生活。

或者,如果您确实想要多个流(例如,避免共享 To: 行),则将它们应用于汇总。
(defn notify [& egroups]
(apply rollup 1 60 (map email (map emails groups))))

希望这会有所帮助,我显然没有复制您的整个配置。

关于clojure.lang.LazySeq 不能转换为 clojure.lang.IFn,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30117542/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com