(ns weepinbell.processor.facade (:require [clojure.spec.alpha :as s] [clojure.core.async :refer [go-loop macro that returns a function, or a reversed comp." [& functions] (apply comp (reverse functions))) (defn assemble-pipeline "Makes a proceesor pipeline. Returns a function that accepts webmention." [{:keys [callbacks storage config]}] (pipe ;; initializer function ;;; turns {:s ... :t ...} to pipeline map that the following functions ;;; pass around; calls :on-receive hook. (fn [wm] (let [{:keys [s t]} wm id (digest (str s t))] ((:on-receive callbacks) {:webmention {:id id :source s :target t}}) {:id id :wm wm :ok? true})) ;; pipeline steps (partial check-storage storage) ;; check if webmention exists verify ;; verify if target is mentioned (partial clean storage callbacks) ;; delete old unverified webmention (partial wrap config) ;; wrap metadata into webmention (partial write storage callbacks)));; write to storage (defn exec-pipeline "Basically wraps (pipeline wm) call inside a try block. catches exceptions and errors so they don't paralyze pipelines." [pipeline wm] (try (pipeline wm) (catch Throwable e (timbre/error "unexpceted exception in pipeline: " (.getMessage e)) (timbre/debug e)))) (defn dispatch-pipeline-loop "Start a loop that takes from wmc and do pipeline when data come in." [n wmc stopped pipeline] (go-loop [wm (