Liking cljdoc? Tell your friends :D

fieldtest.server

Deciding arms for clients and accepting their feedback.

A server is a map built from plug-ins. You can call it in-process, put the handlers in fieldtest.http in front of it, or both. Each plug-in is a plain function that may return a value or a promise:

  • :config-source (fn [] configs) returns the current experiment configs (see fieldtest.config).
  • :selector (fn [{:keys [experiment config sticky-key supported-arms context]}] arm) chooses an arm for one experiment. Defaults to the built-in fieldtest.selector/weighted-hash.
  • :recorder (fn [kind record]) receives every record, where kind is :exposure or :feedback (see fieldtest.records).
  • :error-hook (fn [{:keys [plugin error experiment]}]) receives every plug-in failure. Optional.

Plug-in errors don't make a decide request fail. If the config source fails, the last good configs stay in use. If the selector fails, the experiment gets :default. If the recorder fails, the record is dropped. In each case the error is passed to the error hook.

Deciding arms for clients and accepting their feedback.

A server is a map built from plug-ins. You can call it in-process, put the
handlers in `fieldtest.http` in front of it, or both. Each plug-in is a
plain function that may return a value or a promise:

- `:config-source` `(fn [] configs)` returns the current experiment configs
  (see `fieldtest.config`).
- `:selector` `(fn [{:keys [experiment config sticky-key supported-arms context]}] arm)`
  chooses an arm for one experiment. Defaults to the built-in
  `fieldtest.selector/weighted-hash`.
- `:recorder` `(fn [kind record])` receives every record, where `kind` is
  `:exposure` or `:feedback` (see `fieldtest.records`).
- `:error-hook` `(fn [{:keys [plugin error experiment]}])` receives every
  plug-in failure. Optional.

Plug-in errors don't make a decide request fail. If the config source fails,
the last good configs stay in use. If the selector fails, the experiment
gets `:default`. If the recorder fails, the record is dropped. In each case
the error is passed to the error hook.
raw docstring

decideclj/s

(decide server request)

Decides an arm for each experiment in request and returns a promise of {:decisions [{:experiment :revision :arm :exposure-id} ...]}.

request is {:sticky-key "..." :context {...} :experiments [{:experiment "name" :revision 3 :arms [:default :cdn]} ...]}; the sticky key and context are optional. Every decision, including :default, is recorded as an exposure before the promise resolves.

Rejects with an ex-info of type :fieldtest.server/invalid-request if the request is malformed. Plug-in errors don't cause a rejection.

Decides an arm for each experiment in `request` and returns a promise of
`{:decisions [{:experiment :revision :arm :exposure-id} ...]}`.

`request` is `{:sticky-key "..." :context {...} :experiments [{:experiment
"name" :revision 3 :arms [:default :cdn]} ...]}`; the sticky key and context are
optional. Every decision, including `:default`, is recorded as an exposure before
the promise resolves.

Rejects with an ex-info of type `:fieldtest.server/invalid-request` if the
request is malformed. Plug-in errors don't cause a rejection.
sourceraw docstring

feedback!clj/s

(feedback! server batch)

Validates a batch of feedback and passes each record to the recorder. Returns a promise of {:accepted n}.

Rejects with an ex-info of type :fieldtest.server/invalid-request, without recording anything, if the batch isn't a list or any record in it is invalid. If the recorder fails, the error goes to the error hook and the promise still resolves.

Validates a batch of feedback and passes each record to the recorder.
Returns a promise of `{:accepted n}`.

Rejects with an ex-info of type `:fieldtest.server/invalid-request`, without
recording anything, if the batch isn't a list or any record in it is
invalid. If the recorder fails, the error goes to the error hook and the
promise still resolves.
sourceraw docstring

request-problemclj/s

(request-problem {:keys [sticky-key context experiments] :as request})

Why request is not a valid decide request, or nil when it is.

Why `request` is not a valid decide request, or nil when it is.
sourceraw docstring

serverclj/s

(server {:keys [config-source selector recorder error-hook clock]})

Builds a server from plug-ins. See the namespace docstring.

Also takes :clock, a function returning the current inst, for exposure times.

Builds a server from plug-ins. See the namespace docstring.

Also takes `:clock`, a function returning the current inst, for exposure
times.
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
←Move to previous article
→Move to next article
Ctrl+/Jump to the search field
× close