Class: Themigrator::ScriptPool
- Inherits:
-
Object
- Object
- Themigrator::ScriptPool
- Defined in:
- lib/themigrator/script_pool.rb
Instance Attribute Summary collapse
-
#run_time ⇒ Object
readonly
Returns the value of attribute run_time.
-
#scripts ⇒ Object
readonly
Returns the value of attribute scripts.
Instance Method Summary collapse
- #add_script(script, log_file, attr = {}, &block) ⇒ Object
-
#initialize ⇒ ScriptPool
constructor
A new instance of ScriptPool.
-
#run_and_wait ⇒ Object
Run the scripts returns: * true: All scripts returned 0 * false: Some of the scripts fail.
Constructor Details
#initialize ⇒ ScriptPool
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_time ⇒ Object (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 |
#scripts ⇒ Object (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_wait ⇒ Object
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 |