Module: Resque::Durable

Defined in:
lib/resque/durable.rb,
lib/resque/durable/guid.rb,
lib/resque/durable/monitor.rb,
lib/resque/durable/queue_audit.rb

Defined Under Namespace

Modules: GUID, Monitor Classes: QueueAudit

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/resque/durable.rb', line 7

def self.extended(base)
  base.cattr_accessor :job_timeout
  base.job_timeout = 10.minutes

  base.cattr_accessor :auditor
  base.auditor = QueueAudit
end

Instance Method Details

#around_perform_manage_audit(*args) ⇒ Object



47
48
49
50
51
52
53
54
55
56
# File 'lib/resque/durable.rb', line 47

def around_perform_manage_audit(*args)
  if a = audit(args)
    a.heartbeat!
    return if a.complete?
    yield
    a.complete!
  else
    yield
  end
end

#audit(args) ⇒ Object



35
36
37
38
39
# File 'lib/resque/durable.rb', line 35

def audit(args)
  audit = auditor.find_by_enqueued_id(args.last)
  audit_failed(ArgumentError.new("Could not find audit: #{args.last}")) if audit.nil?
  audit
end

#audit_failed(e, args) ⇒ Object



62
63
64
# File 'lib/resque/durable.rb', line 62

def audit_failed(e, args)
  raise e
end

#build_audit(args) ⇒ Object



58
59
60
# File 'lib/resque/durable.rb', line 58

def build_audit(args)
  auditor.initialize_by_klass_and_args(self, args)
end

#enqueue(*args) ⇒ Object



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

def enqueue(*args)
  if args.last.is_a?(auditor)
    # the audit-is-re-enqueing case
    audit = args.pop
  else
    audit = build_audit(args)
  end

  args << audit.enqueued_id
  begin
    audit.enqueued!
  rescue Exception => e
    audit_failed(e, args)
  end

  Resque.enqueue(self, *args)
rescue Exception => e
  enqueue_failed(e, args)
end

#enqueue_failed(e, args) ⇒ Object



66
67
68
# File 'lib/resque/durable.rb', line 66

def enqueue_failed(e, args)
  raise e
end

#heartbeat(args) ⇒ Object



41
42
43
44
45
# File 'lib/resque/durable.rb', line 41

def heartbeat(args)
  if a = audit(args)
    a.heartbeat!
  end
end