Class: Jackal::Callback
- Inherits:
-
Carnivore::Callback
- Object
- Carnivore::Callback
- Jackal::Callback
- Includes:
- Utils::Config, Utils::Config, Utils::Payload, Utils::Payload
- Defined in:
- lib/jackal/callback.rb
Overview
Jackal customized callback
Instance Method Summary collapse
-
#completed(payload, message) ⇒ Object
Mark payload complete and forward.
-
#failed(payload, message, reason = 'No reason provided') ⇒ Object
Send payload to error handler.
-
#failure_wrap(message) ⇒ Object
Executes block and catches unexpected exceptions if encountered.
-
#forward(payload) ⇒ Object
Forward payload to output source.
-
#job_completed(name, payload, message) ⇒ Object
Mark job as completed.
-
#valid?(message) ⇒ TrueClass, FalseClass
Validity of message.
Methods included from Utils::Config
#config, #config_path, #destination, #source_prefix
Methods included from Utils::Payload
Instance Method Details
#completed(payload, message) ⇒ Object
Mark payload complete and forward
60 61 62 63 64 |
# File 'lib/jackal/callback.rb', line 60 def completed(payload, ) .confirm! info "Processing of #{} complete on this callback" forward(payload) end |
#failed(payload, message, reason = 'No reason provided') ⇒ Object
Send payload to error handler
42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/jackal/callback.rb', line 42 def failed(payload, , reason='No reason provided') error "Processing of #{} failed! Reason: #{reason}" .confirm! destination = "#{source_prefix}_error" source = Carnivore::Supervisor.supervisor[destination] if(source) error "Sending #{} to error handler: #{source}" source.transmit(payload) else error "No error source found for generated source path: #{destination}" info "Processing of message #{} has completed. Message now discarded." end end |
#failure_wrap(message) ⇒ Object
Executes block and catches unexpected exceptions if encountered
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/jackal/callback.rb', line 25 def failure_wrap() abort 'Failure wrap requires block for execution' unless block_given? begin payload = unpack() yield payload rescue => e error "!!! Unexpected failure encountered -> #{e.class}: #{e}" debug "#{e.class}: #{e}\n#{(e.backtrace || []).join("\n")}" failed(payload, , e.) end end |
#forward(payload) ⇒ Object
Forward payload to output source
69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/jackal/callback.rb', line 69 def forward(payload) destination = "#{source_prefix}_output" source = Carnivore::Supervisor.supervisor[destination] if(source) info "Forwarding payload to output destination... (#{source})" debug "Forwarded payload: #{payload.inspect}" source.transmit(payload) else warn "No destination source found for generated source path: #{destination}" info "Processing of message has completed. Message now discarded." end end |
#job_completed(name, payload, message) ⇒ Object
Mark job as completed
87 88 89 90 91 |
# File 'lib/jackal/callback.rb', line 87 def job_completed(name, payload, ) info "Processing of message #{} has completed within this component #{name}" .confirm! forward(payload) end |
#valid?(message) ⇒ TrueClass, FalseClass
Validity of message
16 17 18 19 |
# File 'lib/jackal/callback.rb', line 16 def valid?() m = unpack() block_given? ? yield(m) : true end |