/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

  1. (ns workshop.challenge-3-4
  2. (:require [workshop.workshop-utils :as u]
  3. [clojure.string :as s]))
  4. ;;; Workflows ;;;
  5. (def workflow
  6. [[:read-segments :capitalize-names]
  7. [:capitalize-names :write-segments]])
  8. ;;; Catalogs ;;;
  9. (defn build-catalog
  10. ([] (build-catalog 5 50))
  11. ([batch-size batch-timeout]
  12. [{:onyx/name :read-segments
  13. :onyx/plugin :onyx.plugin.core-async/input
  14. :onyx/type :input
  15. :onyx/medium :core.async
  16. :onyx/batch-size batch-size
  17. :onyx/batch-timeout batch-timeout
  18. :onyx/max-peers 1
  19. :onyx/doc "Reads segments from a core.async channel"}
  20. ;; <<< BEGIN FILL ME IN PART 1 >>>
  21. ;; <<< END FILL ME IN PART 1 >>>
  22. {:onyx/name :write-segments
  23. :onyx/plugin :onyx.plugin.core-async/output
  24. :onyx/type :output
  25. :onyx/medium :core.async
  26. :onyx/batch-size batch-size
  27. :onyx/batch-timeout batch-timeout
  28. :onyx/max-peers 1
  29. :onyx/doc "Writes segments to a core.async channel"}]))
  30. ;;; Functions ;;;
  31. ;; <<< BEGIN FILL ME IN PART 2 >>>
  32. ;; <<< END FILL ME IN PART 2 >>>
  33. ;;; Lifecycles ;;;
  34. (defn inject-writer-ch [event lifecycle]
  35. {:core.async/chan (u/get-output-channel (:core.async/id lifecycle))})
  36. (def writer-lifecycle
  37. {:lifecycle/before-task-start inject-writer-ch})
  38. (defn build-lifecycles []
  39. [{:lifecycle/task :read-segments
  40. :lifecycle/calls :workshop.workshop-utils/in-calls
  41. :core.async/id (java.util.UUID/randomUUID)
  42. :onyx/doc "Injects the core.async reader channel"}
  43. {:lifecycle/task :read-segments
  44. :lifecycle/calls :onyx.plugin.core-async/reader-calls
  45. :onyx/doc "core.async plugin base lifecycle"}
  46. {:lifecycle/task :write-segments
  47. :lifecycle/calls :workshop.challenge-3-4/writer-lifecycle
  48. :core.async/id (java.util.UUID/randomUUID)
  49. :onyx/doc "Injects the core.async writer channel"}
  50. {:lifecycle/task :write-segments
  51. :lifecycle/calls :onyx.plugin.core-async/writer-calls
  52. :onyx/doc "core.async plugin base lifecycle"}])