Class: Themigrator::ScriptPool

Inherits:
Object
  • Object
show all
Defined in:
lib/themigrator/script_pool.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeScriptPool

Returns a new instance of ScriptPool.



6
7
8
9
10
# File 'lib/themigrator/script_pool.rb', line 6

def initialize
  @queue = Queue.new
  @lock = Mutex.new
  @scripts = []
end

Instance Attribute Details

#run_timeObject (readonly)

Returns the value of attribute run_time.



5
6
7
# File 'lib/themigrator/script_pool.rb', line 5

def run_time
  @run_time
end

#scriptsObject (readonly)

Returns the value of attribute scripts.



5
6
7
# File 'lib/themigrator/script_pool.rb', line 5

def scripts
  @scripts
end

Instance Method Details

#add_script(script, log_file, attr = {}, &block) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/themigrator/script_pool.rb', line 12

def add_script(script, log_file, attr = {}, &block)
  s = Script.new(script, log_file, attr, &block)
  @lock.synchronize do
    @scripts << s
  end
  s
end

#run_and_waitObject

Run the scripts returns:

* true: All scripts returned 0
* false: Some of the scripts fail


24
25
26
27
28
29
30
31
32
# File 'lib/themigrator/script_pool.rb', line 24

def run_and_wait
  start = Time.now
  @lock.synchronize do
    start_scripts
    collect_result
  end
ensure
  @run_time = Time.now - start
end