-
Notifications
You must be signed in to change notification settings - Fork 10
/
context.clj
40 lines (36 loc) · 1.43 KB
/
context.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
(ns skyscraper.context)
(defn dissoc-internal
"Dissocs the context keys that shouldn't be carried over to further processing."
[context]
(let [removed-keys #{:processor :url :skyscraper.core/new-items :skyscraper.core/retry}]
(into {}
(remove (fn [[k _]] (or (contains? removed-keys k)
(and (keyword? k)
(= (namespace k) "http")
(not= k :http/cookies)))))
context)))
(defn dissoc-leaf-keys
"Dissocs the context keys that shouldn't appear in the resulting channel
or sequence of leaf nodes."
[context]
(dissoc context
:skyscraper.core/cache-key
:skyscraper.core/current-processor
:skyscraper.core/next-stage
:skyscraper.core/response
:skyscraper.core/stage
:skyscraper.traverse/handler
:skyscraper.traverse/call-protocol
:http/cookies))
(defn describe
"Returns a user-friendly version of a context that doesn't include
Skyscraper's internal keys, but does include the currently running
processor name."
[context]
(let [processor (:skyscraper.core/current-processor context)]
(cond-> context
true dissoc-internal
true dissoc-leaf-keys
true (merge (select-keys context [:processor :url])) ; reattach
processor (assoc :skyscraper.core/current-processor-name (:name processor))
true pr-str)))