Class: Textus::Write::FetchWorker
- Inherits:
-
Object
- Object
- Textus::Write::FetchWorker
- Extended by:
- Contract::DSL
- Defined in:
- lib/textus/write/fetch_worker.rb
Constant Summary collapse
- FETCH_TIMEOUT_SECONDS =
IntakeFetch::FETCH_TIMEOUT_SECONDS
Class Method Summary collapse
Instance Method Summary collapse
-
#call(key) ⇒ Object
call(key) is the primary entry; run is kept as an alias for Orchestrator and FetchAll which call worker.run(key).
-
#initialize(container:, call:) ⇒ FetchWorker
constructor
A new instance of FetchWorker.
- #run(key) ⇒ Object
Methods included from Contract::DSL
arg, contract, contract?, response, summary, surfaces, verb
Constructor Details
#initialize(container:, call:) ⇒ FetchWorker
Returns a new instance of FetchWorker.
16 17 18 19 20 21 22 23 |
# File 'lib/textus/write/fetch_worker.rb', line 16 def initialize(container:, call:) @container = container @call = call @manifest = container.manifest @schemas = container.schemas @events = container.events @rpc = container.rpc end |
Class Method Details
.normalize_action_result(res, format:) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/textus/write/fetch_worker.rb', line 43 def self.normalize_action_result(res, format:) res = res.transform_keys(&:to_s) if res.is_a?(Hash) res ||= {} = res["_meta"] body = res["body"] content = res["content"] case format when "markdown" then { meta: || {}, body: body.to_s, content: nil } when "text" then { meta: {}, body: body.to_s, content: nil } when "json", "yaml" if !content.nil? { meta: || {}, body: nil, content: content } elsif !body.nil? { meta: {}, body: body.to_s, content: nil } else raise Textus::UsageError.new("intake for #{format} returned neither content nor body") end else raise Textus::UsageError.new("unknown format #{format.inspect}") end end |
Instance Method Details
#call(key) ⇒ Object
call(key) is the primary entry; run is kept as an alias for Orchestrator and FetchAll which call worker.run(key).
27 28 29 |
# File 'lib/textus/write/fetch_worker.rb', line 27 def call(key) run(key) end |
#run(key) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/textus/write/fetch_worker.rb', line 31 def run(key) res = @manifest.resolver.resolve(key) mentry = res.entry path = res.path remaining = res.remaining raise UsageError.new("no intake declared for '#{key}'") unless mentry.is_a?(Textus::Manifest::Entry::Intake) before_etag = File.exist?(path) ? Etag.for_file(path) : nil result = fetch_with_events(key, mentry, remaining) persist_and_notify(key, mentry, result, before_etag) end |