Class: Ke::Job

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(task, reporter, opts = {}) ⇒ Job

Returns a new instance of Job.



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/ke/job.rb', line 5

def initialize(task, reporter, opts = {})
  @task = task
  @reporter = reporter
  @opts = opts

  @opts[:report_every] ||= if @task.respond_to?(:total_ticks)
    [1, [@task.total_ticks / 10, 100].min].max
  else
    1
  end
end

Instance Attribute Details

#optsObject (readonly)

Returns the value of attribute opts.



3
4
5
# File 'lib/ke/job.rb', line 3

def opts
  @opts
end

#reporterObject (readonly)

Returns the value of attribute reporter.



3
4
5
# File 'lib/ke/job.rb', line 3

def reporter
  @reporter
end

#taskObject (readonly)

Returns the value of attribute task.



3
4
5
# File 'lib/ke/job.rb', line 3

def task
  @task
end

Instance Method Details

#runObject



23
24
25
26
27
28
29
30
# File 'lib/ke/job.rb', line 23

def run
  task.start
  reporter.print_start
  return_val = yield(self)
  task.complete
  reporter.print_complete
  return_val
end

#tickObject



17
18
19
20
21
# File 'lib/ke/job.rb', line 17

def tick
  task.tick
  reporter.print_tick if task.tick_count % opts[:report_every] == 0
  yield
end