Class: ResqueSerial::SyncJob
- Inherits:
-
Object
- Object
- ResqueSerial::SyncJob
show all
- Extended by:
- Lockable
- Defined in:
- lib/resque-serial/sync_job.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Methods included from Lockable
around_perform_lock, before_perform_lock, clear_lock, get_lock, lock_key, lock_timeout, on_failure_lock, requeue_perform_delay
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
5
6
7
|
# File 'lib/resque-serial/sync_job.rb', line 5
def options
@options
end
|
Class Method Details
.create(target, queue, *args) ⇒ Object
Add a job to queue. Queue name is a class module name
17
18
19
20
21
|
# File 'lib/resque-serial/sync_job.rb', line 17
def create(target, queue, *args)
enqueue_payload target, queue, *args
Resque.enqueue(self, queue)
end
|
.dequeue_payload(queue) ⇒ Object
37
38
39
|
# File 'lib/resque-serial/sync_job.rb', line 37
def dequeue_payload(queue)
YAML.load Resque.redis.lpop "syncjobs:#{queue}"
end
|
.enqueue_payload(target, queue, *args) ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/resque-serial/sync_job.rb', line 23
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.id.to_s if target.scope
options[:timestamp] = target.timestamp if target.timestamp
Resque.redis.rpush "syncjobs:#{queue}", options.to_yaml
end
|
.lock_key(queue) ⇒ Object
12
13
14
|
# File 'lib/resque-serial/sync_job.rb', line 12
def lock_key(queue)
queue
end
|
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/resque-serial/sync_job.rb', line 41
def perform(queue)
options = dequeue_payload queue
model = options[:class].constantize.unscoped.where(id: options[:id]).first
return unless model
model.scope = options.delete(:scope)
model.timestamp = options.delete(:timestamp)
model.send options[:method], *options[:args]
end
|
.queue ⇒ Object
8
9
10
|
# File 'lib/resque-serial/sync_job.rb', line 8
def queue
:sync
end
|
.size_of(queue) ⇒ Object
52
53
54
|
# File 'lib/resque-serial/sync_job.rb', line 52
def size_of(queue)
Resque.redis.llen("syncjobs:#{queue}")
end
|