Class: Pgq::Event

Inherits:
Object
  • Object
show all
Defined in:
lib/pgq/event.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(consumer, event) ⇒ Event

Returns a new instance of Event.



4
5
6
7
8
9
# File 'lib/pgq/event.rb', line 4

def initialize(consumer, event)
  @id = event['ev_id']
  @type = event['ev_type']
  @consumer = consumer
  @data = @consumer.coder.load(event['ev_data']) if event['ev_data']
end

Instance Attribute Details

#consumerObject (readonly)

Returns the value of attribute consumer.



2
3
4
# File 'lib/pgq/event.rb', line 2

def consumer
  @consumer
end

#dataObject (readonly)

Returns the value of attribute data.



2
3
4
# File 'lib/pgq/event.rb', line 2

def data
  @data
end

#idObject (readonly)

Returns the value of attribute id.



2
3
4
# File 'lib/pgq/event.rb', line 2

def id
  @id
end

#typeObject (readonly)

Returns the value of attribute type.



2
3
4
# File 'lib/pgq/event.rb', line 2

def type
  @type
end

Class Method Details

.exception_message(e) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/pgq/event.rb', line 20

def self.exception_message(e)
  <<-EXCEPTION
Exception happend
Error occurs: #{e.class.inspect}(#{e.message})
Backtrace: #{e.backtrace.join("\n") rescue ''}
  EXCEPTION
end

Instance Method Details

#exception_message(e) ⇒ Object

Prepare string with exception details



29
30
31
32
33
34
35
36
37
# File 'lib/pgq/event.rb', line 29

def exception_message(e)
  <<-EXCEPTION
Exception happend
Type: #{@type.inspect}
Data: #{@data.inspect}
Error occurs: #{e.class.inspect}(#{e.message})
Backtrace: #{e.backtrace.join("\n") rescue ''}
  EXCEPTION
end

#failed!(ex) ⇒ Object



11
12
13
14
# File 'lib/pgq/event.rb', line 11

def failed!(ex)
  h = {:class => ex.class.to_s, :message => ex.message, :backtrace => ex.backtrace}
  @consumer.event_failed @id, @consumer.coder.dump(h)
end

#retry!(seconds = 0) ⇒ Object



16
17
18
# File 'lib/pgq/event.rb', line 16

def retry!(seconds = 0)
  @consumer.event_retry(@id, seconds)
end