Class: LogStash::Inputs::Twitter
- Inherits:
-
Base
- Object
- Base
- LogStash::Inputs::Twitter
- Extended by:
- PluginMixins::ValidatorSupport::FieldReferenceValidationAdapter
- Includes:
- PluginMixins::ECSCompatibilitySupport::TargetCheck, PluginMixins::EventSupport::EventFactoryAdapter
- Defined in:
- lib/logstash/inputs/twitter.rb
Overview
Ingest events from the Twitter Streaming API.
Instance Attribute Summary collapse
-
#event_generation_error_count ⇒ Object
readonly
Returns the value of attribute event_generation_error_count.
-
#filter_options ⇒ Object
readonly
Returns the value of attribute filter_options.
Instance Method Summary collapse
- #register ⇒ Object
- #run(queue) ⇒ Object
- #set_stream_client(client) ⇒ Object
- #stop ⇒ Object
- #twitter_options ⇒ Object
Instance Attribute Details
#event_generation_error_count ⇒ Object (readonly)
Returns the value of attribute event_generation_error_count.
24 25 26 |
# File 'lib/logstash/inputs/twitter.rb', line 24 def event_generation_error_count @event_generation_error_count end |
#filter_options ⇒ Object (readonly)
Returns the value of attribute filter_options.
24 25 26 |
# File 'lib/logstash/inputs/twitter.rb', line 24 def @filter_options end |
Instance Method Details
#register ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/logstash/inputs/twitter.rb', line 122 def register if !@use_samples && ( @keywords.nil? && @follows.nil? && @locations.nil? ) raise LogStash::ConfigurationError.new("At least one parameter (follows, locations or keywords) must be specified.") end # monkey patch twitter gem to ignore json parsing error. # at the same time, use our own json parser # this has been tested with a specific gem version, raise if not the same LogStash::Inputs::TwitterPatches.patch @rest_client = Twitter::REST::Client.new { |c| configure(c) } @stream_client = Twitter::Streaming::Client.new { |c| configure(c) } @twitter_options = end |
#run(queue) ⇒ Object
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/logstash/inputs/twitter.rb', line 138 def run(queue) @logger.info("Starting twitter tracking", .clone) # need to pass a clone as it modify this var otherwise # keep track of the amount of non-specific errors rescued and logged - use in testing to verify no errors. # this is because, as yet, we can't have rspec expectations on the logger instance. @event_generation_error_count = 0 begin do_run(queue) rescue Twitter::Error::TooManyRequests => e sleep_for = e.rate_limit.reset_in || @rate_limit_reset_in # 5 minutes default value from config @logger.warn("Twitter too many requests error, sleeping for #{sleep_for}s") Stud.stoppable_sleep(sleep_for) { stop? } retry rescue => e # if a lot of these errors begin to occur, the repeated retry will result in TooManyRequests errors trapped above. @logger.warn("Twitter client error", :message => e., :exception => e.class, :backtrace => e.backtrace, :options => @filter_options) retry end end |
#set_stream_client(client) ⇒ Object
182 183 184 |
# File 'lib/logstash/inputs/twitter.rb', line 182 def set_stream_client(client) @stream_client = client end |
#stop ⇒ Object
174 175 176 |
# File 'lib/logstash/inputs/twitter.rb', line 174 def stop @stream_client = nil end |
#twitter_options ⇒ Object
178 179 180 |
# File 'lib/logstash/inputs/twitter.rb', line 178 def @twitter_options end |