Sha256: db656c88222713e2eab5b255b80cad1dadd5ef179dc34464d552c5ac6c400d51

Contents?: true

Size: 1.08 KB

Versions: 63

Compression:

Stored size: 1.08 KB

Contents

module Picky

  class Scheduler

    attr_reader :parallel

    def initialize options = {}
      @parallel = options[:parallel]
      @factor   = options[:factor] || 2

      configure
    end

    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

    def fork?
      require 'procrastinate'
      parallel && Process.respond_to?(:fork)
    rescue LoadError => e
      warn_procrastinate_missing
      return false
    end
    def warn_procrastinate_missing
      warn_gem_missing 'Procrastinate', 'parallelized indexing (with the procrastinate gem)' unless @gem_missing_warned
      @gem_missing_warned = true
    end

  end

end

Version data entries

63 entries across 63 versions & 1 rubygems

Version Path
picky-4.31.3 lib/picky/scheduler.rb
picky-4.31.2 lib/picky/scheduler.rb
picky-4.31.1 lib/picky/scheduler.rb
picky-4.31.0 lib/picky/scheduler.rb
picky-4.30.0 lib/picky/scheduler.rb
picky-4.29.0 lib/picky/scheduler.rb
picky-4.28.1 lib/picky/scheduler.rb
picky-4.27.1 lib/picky/scheduler.rb
picky-4.27.0 lib/picky/scheduler.rb
picky-4.26.2 lib/picky/scheduler.rb
picky-4.26.1 lib/picky/scheduler.rb
picky-4.26.0 lib/picky/scheduler.rb
picky-4.25.3 lib/picky/scheduler.rb
picky-4.25.2 lib/picky/scheduler.rb
picky-4.25.1 lib/picky/scheduler.rb
picky-4.25.0 lib/picky/scheduler.rb
picky-4.24.0 lib/picky/scheduler.rb
picky-4.23.2 lib/picky/scheduler.rb
picky-4.23.1 lib/picky/scheduler.rb
picky-4.23.0 lib/picky/scheduler.rb