Class: Jackal::Callback

Inherits:
Carnivore::Callback
  • Object
show all
Includes:
Utils::Config, Utils::Config, Utils::Payload, Utils::Payload
Defined in:
lib/jackal/callback.rb

Overview

Jackal customized callback

Instance Method Summary (collapse)

Instance Method Details

- (Object) completed(payload, message)

Mark payload complete and forward

Parameters:

  • payload (Hash)
  • message (Carnivore::Message)


60
61
62
63
64
# File 'lib/jackal/callback.rb', line 60

def completed(payload, message)
  message.confirm!
  info "Processing of #{message} complete on this callback"
  forward(payload)
end

- (Hash) config Originally defined in module Utils::Config

Returns configuration

Returns:

  • (Hash)

    configuration

- (Array) config_path(class_name = self.class.name) Originally defined in module Utils::Config

Returns key path in configuration

Returns:

  • (Array)

    key path in configuration

- (Symbol) destination(direction = :output) Originally defined in module Utils::Config

Generation destination key based on direction

Parameters:

  • direction (Symbol, String) (defaults to: :output)

Returns:

  • (Symbol)

- (Object) failed(payload, message, reason = 'No reason provided')

Send payload to error handler

Parameters:

  • payload (Hash)
  • message (Carnivore::Message)
  • reason (String) (defaults to: 'No reason provided')


42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/jackal/callback.rb', line 42

def failed(payload, message, reason='No reason provided')
  error "Processing of #{message} failed! Reason: #{reason}"
  message.confirm!
  destination = "#{source_prefix}_error"
  source = Carnivore::Supervisor.supervisor[destination]
  if(source)
    error "Sending #{message} to error handler: #{source}"
    source.transmit(payload)
  else
    error "No error source found for generated source path: #{destination}"
    info "Processing of message #{message} has completed. Message now discarded."
  end
end

- (Object) failure_wrap(message)

Executes block and catches unexpected exceptions if encountered

Parameters:

  • message (Carnivore::Message)

Returns:

  • (Object)


25
26
27
28
29
30
31
32
33
34
35
# File 'lib/jackal/callback.rb', line 25

def failure_wrap(message)
  abort 'Failure wrap requires block for execution' unless block_given?
  begin
    payload = unpack(message)
    yield payload
  rescue => e
    error "!!! Unexpected failure encountered -> #{e.class}: #{e}"
    debug "#{e.class}: #{e}\n#{(e.backtrace || []).join("\n")}"
    failed(payload, message, e.message)
  end
end

- (Object) forward(payload)

Forward payload to output source

Parameters:

  • payload (Hash)


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

Parameters:

  • name (String)
  • payload (Hash)
  • message (Carnivore::Message)


87
88
89
90
91
# File 'lib/jackal/callback.rb', line 87

def job_completed(name, payload, message)
  info "Processing of message #{message} has completed within this component #{name}"
  message.confirm!
  forward(payload)
end

- (Smash) new_payload(name, payload, *args) Originally defined in module Utils::Payload

Generate a new payload

Parameters:

  • name (String)
  • payload (Hash)
  • args (Object)

    extra arguments

Returns:

  • (Smash)

- (String) source_prefix Originally defined in module Utils::Config

Returns prefix of source for this callback

Returns:

  • (String)

    prefix of source for this callback

- (Smash) unpack(message) Originally defined in module Utils::Payload

Extract payload from message

Parameters:

  • message (Carnivore::Message)

Returns:

  • (Smash)

- (TrueClass, FalseClass) valid?(message)

Validity of message

Parameters:

  • message (Carnivore::Message)

Returns:

  • (TrueClass, FalseClass)


16
17
18
19
# File 'lib/jackal/callback.rb', line 16

def valid?(message)
  m = unpack(message)
  block_given? ? yield(m) : true
end