Class: Delayed::FakeJob

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

Constant Summary collapse

@@count =
1
@@lock =
Mutex.new

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(queue = nil) ⇒ FakeJob

Returns a new instance of FakeJob.



7
8
9
10
11
12
13
14
15
16
# File 'lib/delayed/fake_job.rb', line 7

def initialize(queue=nil)
  @run_at = DateTime.now
  @attempts = 0
  @queue = queue

  @@lock.synchronize {
    @id = @@count
    @@count += 1
  }
end

Instance Attribute Details

#attemptsObject

Returns the value of attribute attempts.



5
6
7
# File 'lib/delayed/fake_job.rb', line 5

def attempts
  @attempts
end

#idObject

Returns the value of attribute id.



5
6
7
# File 'lib/delayed/fake_job.rb', line 5

def id
  @id
end

#object_idObject

Returns the value of attribute object_id.



5
6
7
# File 'lib/delayed/fake_job.rb', line 5

def object_id
  @object_id
end

#object_typeObject

Returns the value of attribute object_type.



5
6
7
# File 'lib/delayed/fake_job.rb', line 5

def object_type
  @object_type
end

#queueObject

Returns the value of attribute queue.



5
6
7
# File 'lib/delayed/fake_job.rb', line 5

def queue
  @queue
end

#run_atObject

Returns the value of attribute run_at.



5
6
7
# File 'lib/delayed/fake_job.rb', line 5

def run_at
  @run_at
end

Instance Method Details

#deleteObject



27
28
29
# File 'lib/delayed/fake_job.rb', line 27

def delete
  DelayedJobActiveRecordThreaded.logger.info "deleting job #{@id}" if DelayedJobActiveRecordThreaded.logger
end

#invoke_jobObject



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

def invoke_job
  DelayedJobActiveRecordThreaded.logger.info "invoking job #{@id} in queue #{@queue}" if DelayedJobActiveRecordThreaded.logger
  sleep(rand * 5)
end

#performObject



23
24
25
# File 'lib/delayed/fake_job.rb', line 23

def perform
  invoke_job
end

#saveObject



31
32
33
# File 'lib/delayed/fake_job.rb', line 31

def save
  DelayedJobActiveRecordThreaded.logger "saving job #{@id}" if DelayedJobActiveRecordThreaded.logger
end