Class: PoolParty::ScheduleTasks

Inherits:
Object
  • Object
show all
Includes:
ThreadSafeInstance
Defined in:
lib/poolparty/scheduler.rb

Overview

Schedule tasks container

Instance Method Summary collapse

Methods included from ThreadSafeInstance

included

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

#runObject

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

#runningObject



23
# File 'lib/poolparty/scheduler.rb', line 23

def running;@running ||= false;end

#running?Boolean

Returns:

  • (Boolean)


22
# File 'lib/poolparty/scheduler.rb', line 22

def running?;@running == true;end

#tasksObject

Initialize tasks array and run



7
8
9
# File 'lib/poolparty/scheduler.rb', line 7

def tasks
  @_tasks ||= []
end