Class: Picky::Scheduler
Instance Attribute Summary collapse
-
#parallel ⇒ Object
readonly
Returns the value of attribute parallel.
Instance Method Summary collapse
- #configure ⇒ Object
- #fork? ⇒ Boolean
-
#initialize(options = {}) ⇒ Scheduler
constructor
A new instance of Scheduler.
- #warn_procrastinate_missing ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Scheduler
Returns a new instance of Scheduler.
7 8 9 10 11 12 |
# File 'lib/picky/scheduler.rb', line 7 def initialize = {} @parallel = [:parallel] @factor = [:factor] || 2 configure end |
Instance Attribute Details
#parallel ⇒ Object (readonly)
Returns the value of attribute parallel.
5 6 7 |
# File 'lib/picky/scheduler.rb', line 5 def parallel @parallel end |
Instance Method Details
#configure ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/picky/scheduler.rb', line 14 def configure if fork? def schedule &block scheduler.schedule &block end def finish scheduler.join end def scheduler @scheduler ||= create_scheduler end def create_scheduler Procrastinate::Scheduler.start Procrastinate::SpawnStrategy::Default.new(@factor) end else def schedule yield end def finish # Don't do anything. end end end |
#fork? ⇒ Boolean
42 43 44 45 46 47 48 |
# File 'lib/picky/scheduler.rb', line 42 def fork? require 'procrastinate' parallel && Process.respond_to?(:fork) rescue LoadError => e warn_procrastinate_missing return false end |
#warn_procrastinate_missing ⇒ Object
49 50 51 52 |
# File 'lib/picky/scheduler.rb', line 49 def warn_procrastinate_missing warn_gem_missing 'Procrastinate', 'parallelized indexing (with the procrastinate gem)' unless @gem_missing_warned @gem_missing_warned = true end |