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)
-
- (Object) completed(payload, message)
Mark payload complete and forward.
-
- (Hash) config
included
from Utils::Config
Configuration.
-
- (Array) config_path(class_name = self.class.name)
included
from Utils::Config
Key path in configuration.
-
- (Symbol) destination(direction = :output)
included
from Utils::Config
Generation destination key based on direction.
-
- (Object) failed(payload, message, reason = 'No reason provided')
Send payload to error handler.
-
- (Object) failure_wrap(message)
Executes block and catches unexpected exceptions if encountered.
-
- (Object) forward(payload)
Forward payload to output source.
-
- (Object) job_completed(name, payload, message)
Mark job as completed.
-
- (Smash) new_payload(name, payload, *args)
included
from Utils::Payload
Generate a new payload.
-
- (String) source_prefix
included
from Utils::Config
Prefix of source for this callback.
-
- (Smash) unpack(message)
included
from Utils::Payload
Extract payload from message.
-
- (TrueClass, FalseClass) valid?(message)
Validity of message.
Instance Method Details
- (Object) completed(payload, message)
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 |
- (Hash) config Originally defined in module Utils::Config
Returns configuration
- (Array) config_path(class_name = self.class.name) Originally defined in module Utils::Config
Returns key path in configuration
- (Symbol) destination(direction = :output) Originally defined in module Utils::Config
Generation destination key based on direction
- (Object) failed(payload, message, reason = 'No reason provided')
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 |
- (Object) failure_wrap(message)
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 |
- (Object) forward(payload)
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 |
- (Object) job_completed(name, payload, message)
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 |
- (Smash) new_payload(name, payload, *args) Originally defined in module Utils::Payload
Generate a new payload
- (String) source_prefix Originally defined in module Utils::Config
Returns prefix of source for this callback
- (Smash) unpack(message) Originally defined in module Utils::Payload
Extract payload from message
- (TrueClass, FalseClass) valid?(message)
Validity of message
16 17 18 19 |
# File 'lib/jackal/callback.rb', line 16 def valid?() m = unpack() block_given? ? yield(m) : true end |