Class: DCA::Jobs::Job

Inherits:
Object
  • Object
show all
Includes:
Helpers::Logger
Defined in:
lib/dca/jobs/job.rb

Direct Known Subclasses

AnalyzerJob

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helpers::Logger

#logger

Constructor Details

#initialize(options = {}) ⇒ Job

Returns a new instance of Job.



24
25
26
27
28
# File 'lib/dca/jobs/job.rb', line 24

def initialize(options = {})
  @options = options

  trap('QUIT') { shutdown }
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



7
8
9
# File 'lib/dca/jobs/job.rb', line 7

def options
  @options
end

Class Method Details

.create(options = {}) ⇒ Object

Add a job to queue. Queue name is a class module name



14
15
16
# File 'lib/dca/jobs/job.rb', line 14

def self.create(options={})
  Resque.enqueue(self, options)
end

.perform(options = {}) ⇒ Object



18
19
20
21
22
# File 'lib/dca/jobs/job.rb', line 18

def self.perform(options={})
  instance = new options.symbolize_keys!
  instance.safe_perform!
  instance
end

.queueObject



9
10
11
# File 'lib/dca/jobs/job.rb', line 9

def self.queue
  self.to_s.split("::")[-2]
end

Instance Method Details

#destroyObject



47
48
49
# File 'lib/dca/jobs/job.rb', line 47

def destroy

end

#performObject

Raises:

  • (NotImplementedError)


43
44
45
# File 'lib/dca/jobs/job.rb', line 43

def perform
  raise NotImplementedError
end

#safe_perform!Object



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/dca/jobs/job.rb', line 30

def safe_perform!
  perform
  on_success if respond_to?(:on_success)
rescue Exception => exception
  if respond_to?(:on_failure)
    on_failure(exception)
  else
    raise exception
  end
ensure
  destroy
end

#shutdown?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/dca/jobs/job.rb', line 51

def shutdown?
  @shutdown
end