Class: TRMNLP::Poller
- Inherits:
-
Object
- Object
- TRMNLP::Poller
- Defined in:
- lib/trmnlp/poller.rb
Instance Method Summary collapse
-
#initialize(config:, paths:, reporter: Reporter.new) ⇒ Poller
constructor
A new instance of Poller.
- #poll_data ⇒ Object
- #put_webhook(payload) ⇒ Object
Constructor Details
Instance Method Details
#poll_data ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/trmnlp/poller.rb', line 17 def poll_data return unless config.plugin.polling? raise InvalidConfig, 'config must specify polling_url or polling_urls' if config.plugin.polling_urls.empty? data = aggregate_responses write_user_data(data) data # NOTE: trmnlp is a dev tool — a flaky upstream API should surface a warning # and keep the preview server alive, not crash the user's session. We # deliberately swallow here and return {} so the renderer keeps rendering. rescue StandardError => e reporter.info(reporter.yellow("warning: #{e.}")) {} end |
#put_webhook(payload) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/trmnlp/poller.rb', line 32 def put_webhook(payload) write_user_data(wrap_array(JSON.parse(payload))) # NOTE: Same rationale as #poll_data — a bad webhook payload shouldn't take # down the dev server. Report a warning and keep serving. rescue StandardError => e reporter.info(reporter.yellow("webhook warning: #{e.}")) end |