Class: ResqueSerial::AsyncJob

Inherits:
Object
  • Object
show all
Defined in:
lib/resque-serial/async_job.rb

Class Method Summary collapse

Class Method Details

.create(target, queue, *args) ⇒ Object

Add a job to queue. Queue name is a class module name



9
10
11
# File 'lib/resque-serial/async_job.rb', line 9

def create(target, queue, *args)
  Resque.enqueue self, enqueue_payload(target, queue, *args)
end

.enqueue_payload(target, queue, *args) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/resque-serial/async_job.rb', line 13

def enqueue_payload(target, queue, *args)
  method = args.shift()
  options = {
      class: target.class.to_s,
      id: target.id.to_s,
      method: method,
      args: args,
  }
  options[:scope] = target.scope && !target.scope.is_a?(String) ? target.scope.id.to_s : target.scope
  options[:timestamp] = target.timestamp if target.timestamp

  options
end

.perform(options) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/resque-serial/async_job.rb', line 27

def perform(options)
  options.symbolize_keys!
  model = options[:class].constantize.unscoped.find(options[:id])
  model.scope = options.delete(:scope)
  model.timestamp = options.delete(:timestamp)
  model.send options[:method], *options[:args]
end

.queueObject



4
5
6
# File 'lib/resque-serial/async_job.rb', line 4

def queue
  :sync
end