Class: JBackground::Task

Inherits:
Object
  • Object
show all
Defined in:
lib/j_background/task.rb

Direct Known Subclasses

ProcTask

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTask

Returns a new instance of Task.



7
8
9
# File 'lib/j_background/task.rb', line 7

def initialize
  self.logger = JBackground::Base.logger
end

Instance Attribute Details

#loggerObject

Returns the value of attribute logger.



5
6
7
# File 'lib/j_background/task.rb', line 5

def logger
  @logger
end

Instance Method Details

#execute_taskObject



21
22
23
# File 'lib/j_background/task.rb', line 21

def execute_task
  puts "You have not defined a task"
end

#runObject



11
12
13
14
15
16
17
18
19
# File 'lib/j_background/task.rb', line 11

def run
  logger.debug "Background Thread #{Thread.current.object_id} - Executing task: #{self.class.name} #{Time.now}"
  begin
    execute_task
  rescue => e
    logger.error "Background Thread #{Thread.current.object_id} - Error executing task: #{self.class.name} #{e}:\n#{e.backtrace.join('\n')}"
  end
  logger.debug "Background Thread #{Thread.current.object_id} - Finished task: #{self.class.name} #{Time.now}"
end