Module: Resque::Plugins::ResqueUUID::ResqueExtensions

Defined in:
lib/resque/plugins/resque_uuid/resque_extensions.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(extender) ⇒ Object



9
10
11
# File 'lib/resque/plugins/resque_uuid/resque_extensions.rb', line 9

def self.extended(extender)
  extender.send(:alias_method, :push_without_uuid, :push)
end

Instance Method Details

#push(queue, item) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/resque/plugins/resque_uuid/resque_extensions.rb', line 13

def push(queue, item)
  uuid_generated = false

  old_uuid = (item[:uuid] || item['uuid']).to_s.strip

  # don't overwrite existing uuids
  if item.respond_to?(:[]=) && (old_uuid.size == 0)
    item[:uuid] = UUIDTools::UUID.random_create.to_s
    uuid_generated = true
  end


  ret = push_without_uuid(queue, item)

  # TODO (davebenvenuti 6/17/2012) the resque push method has no knowledge of the payload class, so this seems a bit sloppy.  However, I couldn't think of a better way to do it
  if uuid_generated
    payload_class = Util.constantize(item[:class] || item['class']) rescue nil
    payload_class.after_uuid_generated(item[:uuid], *item[:args]) if payload_class && payload_class.respond_to?(:after_uuid_generated)
  end

  ret
end