Class: GovernorBackground::Delayed::Job

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

Overview

A wrapper around ::Delayed::Job.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, job) ⇒ Job

Initializes the job with a job name (passed from GovernorBackground.run) and the original delayed_job job.



8
9
10
11
12
# File 'lib/governor_background/delayed/job.rb', line 8

def initialize(name, job)
  @name = name
  @id = job.try(:id)
  @created_at = Time.now
end

Instance Attribute Details

#created_atObject (readonly)

Returns the value of attribute created_at.



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

def created_at
  @created_at
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

Instance Method Details

#completed?Boolean

Returns true if this job has been completed, false otherwise.

Returns:

  • (Boolean)


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

def completed?
  job_completed?
end

#failed?Boolean

Returns true if this job has failed, false otherwise.

Returns:

  • (Boolean)


32
33
34
# File 'lib/governor_background/delayed/job.rb', line 32

def failed?
  job_failed?
end

#killed?Boolean

Always returns false; as far as I know, you can’t tell if a job has been killed.

Returns:

  • (Boolean)


38
39
40
# File 'lib/governor_background/delayed/job.rb', line 38

def killed?
  false
end

#messageObject

Returns a human readable message describing the status. If the job has failed, this will include the error message, otherwise the status itself will be returned.



56
57
58
59
60
# File 'lib/governor_background/delayed/job.rb', line 56

def message
  (job = delayed_job) && job.failed? ?
    job.last_error.lines.first.chomp.gsub(/^\{/, '') :
    status.humanize
end

#queued?Boolean

Returns true if this job is currently waiting in the queue, false otherwise.

Returns:

  • (Boolean)


16
17
18
# File 'lib/governor_background/delayed/job.rb', line 16

def queued?
  job_queued?
end

#statusObject

Returns the status of the job, which can be any of the boolean methods or unknown.



44
45
46
47
48
49
50
51
# File 'lib/governor_background/delayed/job.rb', line 44

def status
  job = delayed_job
  return 'queued' if job_queued?(job)
  return 'working' if job_working?(job)
  return 'completed' if job_completed?(job)
  return 'failed' if job_failed?(job)
  return 'unknown'
end

#working?Boolean

Returns true if this job is currently being processed, false otherwise.

Returns:

  • (Boolean)


22
23
24
# File 'lib/governor_background/delayed/job.rb', line 22

def working?
  job_working?
end