Class: Rukawa::AbstractJob

Inherits:
Object
  • Object
show all
Extended by:
ActiveSupport::DescendantsTracker
Defined in:
lib/rukawa/abstract_job.rb

Direct Known Subclasses

Job, JobNet

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#parent_job_netObject (readonly)

Returns the value of attribute parent_job_net.



7
8
9
# File 'lib/rukawa/abstract_job.rb', line 7

def parent_job_net
  @parent_job_net
end

Class Method Details

.add_skip_rule(callable_or_symbol) ⇒ Object



13
14
15
# File 'lib/rukawa/abstract_job.rb', line 13

def add_skip_rule(callable_or_symbol)
  self.skip_rules = skip_rules + [callable_or_symbol]
end

.descriptionObject Also known as: desc



17
18
19
# File 'lib/rukawa/abstract_job.rb', line 17

def description
  @description
end

.set_description(body) ⇒ Object Also known as: set_desc



22
23
24
# File 'lib/rukawa/abstract_job.rb', line 22

def set_description(body)
  @description = body
end

Instance Method Details

#elapsed_time_from(time = Time.now) ⇒ Object



43
44
45
46
47
48
# File 'lib/rukawa/abstract_job.rb', line 43

def elapsed_time_from(time = Time.now)
  return finished_at - started_at if started_at && finished_at
  return time - started_at if started_at

  nil
end

#formatted_elapsed_time_from(time = Time.now) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/rukawa/abstract_job.rb', line 50

def formatted_elapsed_time_from(time = Time.now)
  elapsed = elapsed_time_from(time)
  return "N/A" unless elapsed

  hour = elapsed.to_i / 3600
  min = (elapsed - hour * 3600).to_i / 60
  sec = (elapsed - hour * 3600 - min * 60).to_i

  hour_format = hour > 0 ? "%dh " % hour : ""
  min_format = hour > 0 || min > 0 ? "%dm " % min : ""
  sec_format = "#{sec}s"
  "#{hour_format}#{min_format}#{sec_format}"
end

#inspectObject



32
33
34
# File 'lib/rukawa/abstract_job.rb', line 32

def inspect
  to_s
end

#nameObject



28
29
30
# File 'lib/rukawa/abstract_job.rb', line 28

def name
  self.class.name || self.class.to_s
end

#skip?Boolean

Returns:

  • (Boolean)


36
37
38
39
40
41
# File 'lib/rukawa/abstract_job.rb', line 36

def skip?
  parent_skip = @parent_job_net ? @parent_job_net.skip? : false
  parent_skip || skip_rules.inject(false) do |cond, rule|
    cond || rule.is_a?(Symbol) ? method(rule).call : rule.call(self)
  end
end