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.
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_time ⇒ Object (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 |
#scripts ⇒ Object (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_wait ⇒ Object
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 |