Class: Jack::Queues::Task

Inherits:
Task
  • Object
show all
Defined in:
lib/jack/queues.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.default_connection_argsObject

Returns the value of attribute default_connection_args.



44
45
46
# File 'lib/jack/queues.rb', line 44

def default_connection_args
  @default_connection_args
end

Instance Attribute Details

#connection_argsObject

Returns the value of attribute connection_args.



13
14
15
# File 'lib/jack/queues.rb', line 13

def connection_args
  @connection_args
end

#optionsObject

Returns the value of attribute options.



14
15
16
# File 'lib/jack/queues.rb', line 14

def options
  @options
end

#queue_nameObject

Returns the value of attribute queue_name.



12
13
14
# File 'lib/jack/queues.rb', line 12

def queue_name
  @queue_name
end

Class Method Details

.queue_task(name, options = {}, &block) ⇒ Object



47
48
49
50
51
52
53
# File 'lib/jack/queues.rb', line 47

def self.queue_task(name, options = {}, &block)
  task = define_task(name, &block)
  task.queue_name      = options.delete(:queue_name) || name
  task.options         = options
  task.connection_args = options.delete(:connect) || default_connection_args
  task
end

Instance Method Details

#executeObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/jack/queues.rb', line 26

def execute
  task = lambda do
    if messages.empty?
      false
    else
      super
      (messages - kept).each do |msg|
        delete msg
      end
      kept.empty?
    end
  end
  while task.call
    @messages = nil
  end
end

#keep(*messages) ⇒ Object



20
21
22
23
24
# File 'lib/jack/queues.rb', line 20

def keep(*messages)
  messages.flatten!
  messages.uniq!
  kept.push *messages
end

#keptObject



16
17
18
# File 'lib/jack/queues.rb', line 16

def kept
  @kept ||= []
end