/src/workshop/challenge_3_4.clj
https://github.com/onyx-platform/learn-onyx · Clojure · 69 lines · 44 code · 17 blank · 8 comment · 0 complexity · b8b4b867b2d4576c8ed2525a43bba22c MD5 · raw file
- (ns workshop.challenge-3-4
- (:require [workshop.workshop-utils :as u]
- [clojure.string :as s]))
- ;;; Workflows ;;;
- (def workflow
- [[:read-segments :capitalize-names]
- [:capitalize-names :write-segments]])
- ;;; Catalogs ;;;
- (defn build-catalog
- ([] (build-catalog 5 50))
- ([batch-size batch-timeout]
- [{:onyx/name :read-segments
- :onyx/plugin :onyx.plugin.core-async/input
- :onyx/type :input
- :onyx/medium :core.async
- :onyx/batch-size batch-size
- :onyx/batch-timeout batch-timeout
- :onyx/max-peers 1
- :onyx/doc "Reads segments from a core.async channel"}
- ;; <<< BEGIN FILL ME IN PART 1 >>>
- ;; <<< END FILL ME IN PART 1 >>>
- {:onyx/name :write-segments
- :onyx/plugin :onyx.plugin.core-async/output
- :onyx/type :output
- :onyx/medium :core.async
- :onyx/batch-size batch-size
- :onyx/batch-timeout batch-timeout
- :onyx/max-peers 1
- :onyx/doc "Writes segments to a core.async channel"}]))
- ;;; Functions ;;;
- ;; <<< BEGIN FILL ME IN PART 2 >>>
- ;; <<< END FILL ME IN PART 2 >>>
- ;;; Lifecycles ;;;
- (defn inject-writer-ch [event lifecycle]
- {:core.async/chan (u/get-output-channel (:core.async/id lifecycle))})
- (def writer-lifecycle
- {:lifecycle/before-task-start inject-writer-ch})
- (defn build-lifecycles []
- [{:lifecycle/task :read-segments
- :lifecycle/calls :workshop.workshop-utils/in-calls
- :core.async/id (java.util.UUID/randomUUID)
- :onyx/doc "Injects the core.async reader channel"}
- {:lifecycle/task :read-segments
- :lifecycle/calls :onyx.plugin.core-async/reader-calls
- :onyx/doc "core.async plugin base lifecycle"}
- {:lifecycle/task :write-segments
- :lifecycle/calls :workshop.challenge-3-4/writer-lifecycle
- :core.async/id (java.util.UUID/randomUUID)
- :onyx/doc "Injects the core.async writer channel"}
- {:lifecycle/task :write-segments
- :lifecycle/calls :onyx.plugin.core-async/writer-calls
- :onyx/doc "core.async plugin base lifecycle"}])