Class: Delayed::JobTracking

Inherits:
Struct
  • Object
show all
Defined in:
lib/delayed/job_tracking.rb

Overview

Used when a block of code wants to track what jobs are created, for instance in tests. Delayed::Job.track_jobs { …block… } returns a JobTracking object Right now this just tracks created jobs, it could be expanded to track a lot more about what’s going on in Delayed Jobs as it’s needed.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeJobTracking

Returns a new instance of JobTracking.



28
29
30
31
32
# File 'lib/delayed/job_tracking.rb', line 28

def initialize
  super
  self.created = []
  @lock = Mutex.new
end

Instance Attribute Details

#createdObject

Returns the value of attribute created

Returns:

  • (Object)

    the current value of created



9
10
11
# File 'lib/delayed/job_tracking.rb', line 9

def created
  @created
end

Class Method Details

.job_created(job) ⇒ Object



18
19
20
# File 'lib/delayed/job_tracking.rb', line 18

def self.job_created(job)
  @current_tracking.try(:job_created, job)
end

.trackObject



10
11
12
13
14
15
16
# File 'lib/delayed/job_tracking.rb', line 10

def self.track
  @current_tracking = new
  yield
  tracking = @current_tracking
  @current_tracking = nil
  tracking
end

Instance Method Details

#job_created(job) ⇒ Object



22
23
24
25
26
# File 'lib/delayed/job_tracking.rb', line 22

def job_created(job)
  return unless job

  @lock.synchronize { created << job }
end