Class: AllGems::Runner
- Inherits:
-
Object
- Object
- AllGems::Runner
- Defined in:
- lib/allgems/Runner.rb
Instance Method Summary collapse
- #do_sync ⇒ Object
-
#initialize(args = {}) ⇒ Runner
constructor
- :db_path
- path to sqlite database :runners
- maximum number of threads to use :interval
-
how often to update documents (useless if using cron).
-
#stop(now = false) ⇒ Object
Stop the runner.
-
#sync ⇒ Object
Get the list of gems we need and load up the pool.
Constructor Details
#initialize(args = {}) ⇒ Runner
- :db_path
-
path to sqlite database
- :runners
-
maximum number of threads to use
- :interval
-
how often to update documents (useless if using cron)
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/allgems/Runner.rb', line 11 def initialize(args={}) raise ArgumentError.new('Expecting path to database') unless args[:db_path] @db = Sequel.connect("sqlite://#{args[:db_path]}") AllGems.initialize_db(@db) @pool = ActionPool::Pool.new(:max_threads => args[:runners] ? args[:runners] : 10) GemWorker.setup @index = IndexBuilder.new(:database => @db) @interval = args[:interval] ? args[:interval] : nil @timer = nil @lock = Mutex.new @guard = ConditionVariable.new @stop = false end |
Instance Method Details
#do_sync ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/allgems/Runner.rb', line 25 def do_sync if(@interval) @timer = ActionTimer::Timer.new(:pool => @pool) sync @timer.add(@interval){ sync } else sync end end |
#stop(now = false) ⇒ Object
Stop the runner
50 51 52 53 54 55 56 |
# File 'lib/allgems/Runner.rb', line 50 def stop(now=false) @timer.clear if @timer @stop = true @lock.synchronize{@guard.broadcast} @pool.shutdown(now) GemWorker.pool.shutdown(now) end |
#sync ⇒ Object
Get the list of gems we need and load up the pool. Then take a nap until the pool gets bored and wakes us up
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/allgems/Runner.rb', line 36 def sync Gem.refresh Thread.new do @pool.add_jobs(@index.build_array(@index.local_array).collect{|x| lambda{GemWorker.process({:database => @db}.merge(x))}}) end begin @pool << lambda{@lock.synchronize{@guard.signal}} @lock.synchronize{@guard.wait(@lock)} rescue StandardError => boom AllGems.logger.error boom.to_s retry unless @stop end end |