Class: NFAgent::Submitter
- Includes:
- EM::Deferrable
- Defined in:
- lib/nfagent/submitter.rb
Instance Attribute Summary collapse
-
#host ⇒ Object
Returns the value of attribute host.
Class Method Summary collapse
-
.resubmit_failed_dumps ⇒ Object
TODO: Change attempt logic Add the next timestamp for when submission should be attenpted again to the end of the filename.
-
.run_every(seconds) ⇒ Object
Actually runs the submitter every ‘seconds’ seconds after the last one completes.
Instance Method Summary collapse
-
#initialize(payload) ⇒ Submitter
constructor
A new instance of Submitter.
- #perform ⇒ Object
Constructor Details
#initialize(payload) ⇒ Submitter
Returns a new instance of Submitter.
6 7 8 |
# File 'lib/nfagent/submitter.rb', line 6 def initialize(payload) @payload = payload end |
Instance Attribute Details
#host ⇒ Object
Returns the value of attribute host.
4 5 6 |
# File 'lib/nfagent/submitter.rb', line 4 def host @host end |
Class Method Details
.resubmit_failed_dumps ⇒ Object
TODO: Change attempt logic Add the next timestamp for when submission should be attenpted again to the end of the filename
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/nfagent/submitter.rb', line 40 def self.resubmit_failed_dumps submitter = Submitter.new(Config.client_key) dump_dir = Dir.new(Config.dump_dir) dump_dir.entries.select { |e| not e =~ /^\./ }.each do |entry| Log.info "Resubmitting #{entry}" payload = Payload.read_from_file(entry) submitter = self.new(payload) submitter.callback { |payload| payload.destroy! } submitter.errback { |payload| if payload.attempt > 16 payload.destroy! else payload.try_again_later end } submitter.perform end end |
.run_every(seconds) ⇒ Object
Actually runs the submitter every ‘seconds’ seconds after the last one completes
29 30 31 32 33 34 35 36 |
# File 'lib/nfagent/submitter.rb', line 29 def self.run_every(seconds) callback = proc { run_every(seconds) } EM::add_timer(seconds) do EM::defer(nil, callback) do resubmit_failed_dumps end end end |
Instance Method Details
#perform ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/nfagent/submitter.rb', line 10 def perform @payload.increment_attempt! fail(@payload) unless [ 1, 2, 4, 8, 16 ].include?(@payload.attempt) Log.info "Submitting Payload: #{@payload.checksum}, Attempt #{@payload.attempt}, (#{@payload.size} bytes, #{@payload.line_count} lines)" @payload.lock do response = Client.post(:collector, @payload.to_hash) if response.ok? succeed(@payload) Log.info("Submitted #{@payload.line_count} lines") else Log.error "Submission Failed: #{response.}" fail(@payload) end end end |