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.



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

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

Instance Attribute Details

#run_timeObject (readonly)

Returns the value of attribute run_time.



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

def run_time
  @run_time
end

#scriptsObject (readonly)

Returns the value of attribute scripts.



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

def scripts
  @scripts
end

Instance Method Details

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



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

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


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

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