Reusable throttled email function

21 views
Skip to first unread message

Ahmad Khayyat

unread,
Dec 24, 2019, 7:30:30 AM12/24/19
to Riemann Users
Hello,

I'm trying to create an email-daily function that I can use in various places in my config. However, I keep encountering different problems that prevent such a function from working.

Here is a complete config representing my current attempt:


Relevant parts:

;; Email
(let [mail-opts {:host "localhost"
                 :port 25
                 :from "root@localhost"
                 :to   ["root@localhost"]}]
 
  (def email (mailer mail-opts))
  (def email-daily (throttle 1 86400 (email)))
  )

(streams ...
  (where ...
    email-daily)
  (where ...
    email-daily)
)

Although this does not produce any errors, it only sends a single email across all streams. For example, in the linked example config (and snippet above), I expect two daily emails, one per where-clause. Instead, I only receive a single email per day overall (one where-clause gets to send an email).

1. Why does this config result in this behavior?
2. How do I get the desired behavior (a daily email for every stream in which email-daily is used)?

Seva Kobylin

unread,
Dec 24, 2019, 7:36:43 AM12/24/19
to rieman...@googlegroups.com
something like
(streams ...
  (where ...
   throttle 1 86400(email))
  (where ...
   throttle 1 86400(email))
)

?

24 дек. 2019 г., в 15:30, Ahmad Khayyat <akha...@gmail.com> написал(а):

--
You received this message because you are subscribed to the Google Groups "Riemann Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to riemann-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/riemann-users/12a18500-1f03-4832-9081-333506974fb7%40googlegroups.com.

ap...@aphyr.com

unread,
Dec 24, 2019, 7:44:37 AM12/24/19
to rieman...@googlegroups.com
Close! You want to change the def to a defn on email-daily, so you're creating a fresh throttle stream on every invocation. Then wrap each use of email in parens, to invoke it. The howto has a section on understanding the streaming model that might prove helpful!

Ahmad Khayyat

unread,
Dec 24, 2019, 7:54:06 AM12/24/19
to Riemann Users
I tried that already, but it felt like a step backwards as it generated errors.

;; Email
(let [mail-opts {:host "localhost"
                 :port 25
                 :from "root@localhost"
                 :to   ["root@localhost"]}]

  (def email (mailer mail-opts))
  (defn email-daily (throttle 1 86400 (email)))
  )

(streams ...
  (where ...
    (email-daily))
  (where ...
    (email-daily))
)

Results in:

ERROR [2019-12-24 15:49:13,501] main - riemann.bin - Couldn't start
clojure.lang.Compiler$CompilerException: clojure.lang.ExceptionInfo: Call to clojure.core/defn did not conform to spec:
In: [1 0] val: throttle fails spec: :clojure.core.specs.alpha/arg-list at: [:args :bs :arity-n :bodies :args] predicate: vector?
In: [1] val: (throttle 1 86400 (email)) fails spec: :clojure.core.specs.alpha/arg-list at: [:args :bs :arity-1 :args] predicate: vector?
 {:clojure.spec.alpha/problems ({:path [:args :bs :arity-1 :args], :pred clojure.core/vector?, :val (throttle 1 86400 (email)), :via [:clojure.core.specs.alpha/defn-args :clojure.core.specs.alpha/args+body :clojure.core.specs.alpha/arg-list :clojure.core.specs.alpha/arg-list], :in [1]} {:path [:args :bs :arity-n :bodies :args], :pred clojure.core/vector?, :val throttle, :via [:clojure.core.specs.alpha/defn-args :clojure.core.specs.alpha/args+body :clojure.core.specs.alpha/args+body :clojure.core.specs.alpha/args+body :clojure.core.specs.alpha/arg-list :clojure.core.specs.alpha/arg-list], :in [1 0]}), :clojure.spec.alpha/spec #object[clojure.spec.alpha$regex_spec_impl$reify__2436 0x2435c6ae "clojure.spec.alpha$regex_spec_impl$reify__2436@2435c6ae"], :clojure.spec.alpha/value (email-daily (throttle 1 86400 (email))), :clojure.spec.alpha/args (email-daily (throttle 1 86400 (email)))}, compiling:(.../riemann.config:23:3)
        at clojure.lang.Compiler.checkSpecs(Compiler.java:6891)
        at clojure.lang.Compiler.macroexpand1(Compiler.java:6907)
        at clojure.lang.Compiler.analyzeSeq(Compiler.java:6989)
        at clojure.lang.Compiler.analyze(Compiler.java:6773)
        at clojure.lang.Compiler.analyze(Compiler.java:6729)
        at clojure.lang.Compiler$BodyExpr$Parser.parse(Compiler.java:6100)
        at clojure.lang.Compiler$LetExpr$Parser.parse(Compiler.java:6420)
        at clojure.lang.Compiler.analyzeSeq(Compiler.java:7003)
        at clojure.lang.Compiler.analyze(Compiler.java:6773)
        at clojure.lang.Compiler.analyze(Compiler.java:6729)
        at clojure.lang.Compiler$BodyExpr$Parser.parse(Compiler.java:6100)
        at clojure.lang.Compiler$FnMethod.parse(Compiler.java:5460)
        at clojure.lang.Compiler$FnExpr.parse(Compiler.java:4022)
        at clojure.lang.Compiler.analyzeSeq(Compiler.java:7001)
        at clojure.lang.Compiler.analyze(Compiler.java:6773)
        at clojure.lang.Compiler.eval(Compiler.java:7059)
        at clojure.lang.Compiler.load(Compiler.java:7514)
        at clojure.lang.Compiler.loadFile(Compiler.java:7452)
        at clojure.lang.RT$3.invoke(RT.java:325)
        at riemann.config$include.invokeStatic(config.clj:450)
        at riemann.config$include.invoke(config.clj:427)
        at riemann.bin$_main$fn__14384.invoke(bin.clj:147)
        at riemann.bin$run_app_BANG_.invokeStatic(bin.clj:131)
        at riemann.bin$run_app_BANG_.invoke(bin.clj:123)
        at riemann.bin$_main.invokeStatic(bin.clj:147)
        at riemann.bin$_main.doInvoke(bin.clj:135)
        at clojure.lang.RestFn.invoke(RestFn.java:425)
        at clojure.lang.AFn.applyToHelper(AFn.java:156)
        at clojure.lang.RestFn.applyTo(RestFn.java:132)
        at riemann.bin.main(Unknown Source)
Caused by: clojure.lang.ExceptionInfo: Call to clojure.core/defn did not conform to spec:
In: [1 0] val: throttle fails spec: :clojure.core.specs.alpha/arg-list at: [:args :bs :arity-n :bodies :args] predicate: vector?
In: [1] val: (throttle 1 86400 (email)) fails spec: :clojure.core.specs.alpha/arg-list at: [:args :bs :arity-1 :args] predicate: vector?

        at clojure.core$ex_info.invokeStatic(core.clj:4739)
        at clojure.core$ex_info.invoke(core.clj:4739)
        at clojure.spec.alpha$macroexpand_check.invokeStatic(alpha.clj:689)
        at clojure.spec.alpha$macroexpand_check.invoke(alpha.clj:681)
        at clojure.lang.AFn.applyToHelper(AFn.java:156)
        at clojure.lang.AFn.applyTo(AFn.java:144)
        at clojure.lang.Var.applyTo(Var.java:702)
        at clojure.lang.Compiler.checkSpecs(Compiler.java:6889)
        ... 29 common frames omitted

?

To unsubscribe from this group and stop receiving emails from it, send an email to rieman...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Riemann Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rieman...@googlegroups.com.

Ahmad Khayyat

unread,
Dec 24, 2019, 7:57:50 AM12/24/19
to Riemann Users
Hmm..

  (defn email-daily [] (throttle 1 86400 (email)))

seems to work!


On Tuesday, December 24, 2019 at 3:44:37 PM UTC+3, aphyr wrote:
?

To unsubscribe from this group and stop receiving emails from it, send an email to rieman...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Riemann Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rieman...@googlegroups.com.

ap...@aphyr.com

unread,
Dec 24, 2019, 8:58:13 AM12/24/19
to rieman...@googlegroups.com
Bingo. Defn takes an argument list: [] for no args. :)

To unsubscribe from this group and stop receiving emails from it, send an email to riemann-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/riemann-users/7378d77d-a463-4520-86cd-714f40e646d7%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages