Class: PoolParty::ScheduleTasks
- Includes:
- ThreadSafeInstance
- Defined in:
- lib/poolparty/scheduler.rb
Overview
Schedule tasks container
Instance Method Summary collapse
-
#<<(a, *args) ⇒ Object
(also: #push)
Add a task in a new thread.
-
#run ⇒ Object
Synchronize the running threaded tasks.
- #running ⇒ Object
- #running? ⇒ Boolean
-
#tasks ⇒ Object
Initialize tasks array and run.
Methods included from ThreadSafeInstance
Instance Method Details
#<<(a, *args) ⇒ Object Also known as: push
Add a task in a new thread
25 26 27 |
# File 'lib/poolparty/scheduler.rb', line 25 def <<(a, *args) tasks << a end |
#run ⇒ Object
Synchronize the running threaded tasks
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/poolparty/scheduler.rb', line 11 def run unless tasks.empty? && !running? running = true pool = ThreadPool.new(10) tasks.reject! do |task| pool.process {task.call} end pool.join() # When all the tasks are done running = false end end |
#running ⇒ Object
23 |
# File 'lib/poolparty/scheduler.rb', line 23 def running;@running ||= false;end |
#running? ⇒ Boolean
22 |
# File 'lib/poolparty/scheduler.rb', line 22 def running?;@running == true;end |
#tasks ⇒ Object
Initialize tasks array and run
7 8 9 |
# File 'lib/poolparty/scheduler.rb', line 7 def tasks @_tasks ||= [] end |