Class: Twirl::Item

Inherits:
Object
  • Object
show all
Defined in:
lib/twirl/item.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, value, client, instrumenter = nil) ⇒ Item

Returns a new instance of Item.



14
15
16
17
18
19
# File 'lib/twirl/item.rb', line 14

def initialize(key, value, client, instrumenter = nil)
  @key = key
  @value = value
  @client = client
  @instrumenter = instrumenter || Instrumenters::Noop
end

Instance Attribute Details

#clientObject (readonly)

Private: The client that popped the item.



12
13
14
# File 'lib/twirl/item.rb', line 12

def client
  @client
end

#keyObject (readonly)

Public: The key of the item.



6
7
8
# File 'lib/twirl/item.rb', line 6

def key
  @key
end

#valueObject (readonly)

Public: The value of the item.



9
10
11
# File 'lib/twirl/item.rb', line 9

def value
  @value
end

Instance Method Details

#abortObject

Public: Something went wrong processing.



32
33
34
35
36
37
38
39
# File 'lib/twirl/item.rb', line 32

def abort
  @instrumenter.instrument "op.twirl" do |payload|
    payload[:op] = :item_abort
    payload[:queue_name] = @key

    @client.abort @key
  end
end

#closeObject

Public: Acknowledge that we are done processing the item.



22
23
24
25
26
27
28
29
# File 'lib/twirl/item.rb', line 22

def close
  @instrumenter.instrument "op.twirl" do |payload|
    payload[:op] = :item_close
    payload[:queue_name] = @key

    @client.close @key
  end
end

#eql?(other) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)


41
42
43
44
45
46
# File 'lib/twirl/item.rb', line 41

def eql?(other)
  self.class.eql?(other.class) &&
    @key == other.key &&
    @value == other.value &&
    @client == other.client
end