Skip to content
akshat edited this page Oct 19, 2023 · 5 revisions

Goose uses Clojure Spec to perform validations. As a bonus, specs also document expected input/output.

Enabling Specs

  • Goose validates inputs for single-use functions
    • rmq/new-producer, worker/start... are called only during initialization & considered single-use

  • Instrumentation/Validation is turned off by default for frequently-used functions
    • perform-async, perform-at... are called frequently during runtime & considered frequently-used
  • We/Clojure community strongly recommends enabling Specs in Development, Testing & Staging env
  • When tested, Specs can be disabled in production to reduce validations overhead
    • Job enqueue performance increases by 40% when specs are disabled
  • Goose exposes functions to enable/disable Specs for frequently-called functions
(ns my-ns
  (:require
    [goose.client :as c]
    [goose.specs :as specs]))

;;; Enabling Specs.
(specs/instrument)

(c/perform-async client-opts `incorrect-fn :foo :bar)
Execution error - invalid arguments to goose.client/perform-async at (my_ns.clj:7).
my-app/incorrect-fn - failed: resolve at: [:execute-fn-sym] spec: :goose.specs/fn-sym

;;; Disabling Specs.
(specs/unstrument)

Viewing documentation

;;; Specs & REPL namespace must be loaded to view docs.
(require '[goose.specs]
         '[clojure.repl])

(doc goose.client/perform-async)
-------------------------
goose.client/perform-async
([opts execute-fn-sym & args])
  Enqueues a function for async execution.

  ### Args
  `client-opts`    : Map of `:broker`, `:queue` & `:retry-opts`.\
  Example          : [[default-opts]]

  `execute-fn-sym` : A fully-qualified function symbol called by worker.\
  Example          : ```my-fn`, ```ns-alias/my-fn`, `'fully-qualified-ns/my-fn`

  `args`           : Variadic values provided in given order when invoking `execute-fn-sym`.\
   Given values must be serializable by `ptaoussanis/nippy`.

  ### Usage
  (perform-async client-opts `send-emails "subject" "body" [:user-1 :user-2])

  - [Getting Started wiki](https://github.com/nilenso/goose/wiki/Getting-Started).
Spec
  args: (cat :opts :goose.specs/client-opts :execute-fn-sym :goose.specs/fn-sym :args (* :goose.specs/args-serializable?))
  ret: map?

Previous: API        Next: Serializing Custom data-types

Clone this wiki locally