Class: TaskTempest::Task

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Task

Returns a new instance of Task.



12
13
14
15
# File 'lib/task_tempest/task.rb', line 12

def initialize(*args)
  @id = generate_id
  @args = args
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



9
10
11
# File 'lib/task_tempest/task.rb', line 9

def args
  @args
end

#executionObject

Returns the value of attribute execution.



10
11
12
# File 'lib/task_tempest/task.rb', line 10

def execution
  @execution
end

#idObject (readonly)

Returns the value of attribute id.



9
10
11
# File 'lib/task_tempest/task.rb', line 9

def id
  @id
end

Instance Method Details

#format_log(message, show_duration = false) ⇒ Object



39
40
41
42
43
# File 'lib/task_tempest/task.rb', line 39

def format_log(message, show_duration = false)
  s = "{#{id}} <#{self.class}> #{message}"
  s += " #{execution.duration.round(3)}" if show_duration and execution.finished?
  s
end

#init(options = {}) ⇒ Object



17
18
19
20
21
# File 'lib/task_tempest/task.rb', line 17

def init(options = {})
  @id = options[:id] if options[:id]
  @logger = TaskLogger.new(options[:logger], self) if options[:logger]
  self
end

#loggerObject



31
32
33
# File 'lib/task_tempest/task.rb', line 31

def logger
  @logger ||= TaskLogger.new(Logger.new(STDOUT), self)
end

#runObject



23
24
25
# File 'lib/task_tempest/task.rb', line 23

def run
  Kernel.record_requires!{ start(*args) }
end

#start(*args) ⇒ Object



27
28
29
# File 'lib/task_tempest/task.rb', line 27

def start(*args)
  raise "not implemented"
end

#to_messageObject



35
36
37
# File 'lib/task_tempest/task.rb', line 35

def to_message
  [id, self.class.name, *args]
end