Database Reference
In-Depth Information
Getting ready
We'll use the dependencies and requirements that we did in the Monitoring processing with
watchers recipe. For this recipe, we just need to add a two more functions to them.
How to do it…
1.
The main difference from the last recipe is the watch function. Here's the new one:
(defn debug-watch [watch-key watch-agent old-state new-state]
(let [output (str watch-key
": "
(pr-str old-state)
" => "
(pr-str new-state)
\newline)]
(print output)))
2.
Of course, the main function that creates the system and runs it is different.
I've highlighted the changes:
(defn watch-debugging
[input-file]
(let [reader (agent
(seque
(mapcat
lazy-read-csv
input-files)))
caster (agent nil)
sink (agent [])
counter (ref 0)
done (ref false)]
(add-watch caster :counter
(partial watch-caster counter))
(add-watch caster :debug debug-watch)
(send reader read-row caster sink done)
(wait-for-it 250 done)
{:results @sink
:count-watcher @counter}))
3.
Now, when we run this processing system, we get a lot of debugging output:
user=> (:count-watcher (watch-debugging (take 2 data-files)))
:debug: [1990 "|0028670|" "|C00186288|" "|N00001783|" 1000
"06/15/1990" "|C4100|" "|24K|" "|D|" "|H6MI16034|"] => [1990
"|0028677|" "|C00186288|" "|N00007967|" 2000 "06/15/1990"
"|C4100|" "|24K|" "|D|" "|H6WA05023|"]
 
Search WWH ::




Custom Search