Sha256: 31d0e8151fe220bbc8f05857b875456019259116c5d810877f0f055051961c4e

Contents?: true

Size: 861 Bytes

Versions: 5

Compression:

Stored size: 861 Bytes

Contents

require "active_support/core_ext/string"

module CronoTrigger
  module Worker
    def initialize
      @stop_flag = ServerEngine::BlockingFlag.new
      @model_queue = Queue.new
      CronoTrigger.config.model_names.each do |model_name|
        model = model_name.classify.constantize
        @model_queue << model
      end
      @executor = Concurrent::ThreadPoolExecutor.new(
        min_threads: 1,
        max_threads: CronoTrigger.config.executor_thread,
      )
      ActiveRecord::Base.logger = logger
    end

    def run
      polling_threads = CronoTrigger.config.polling_thread.times.map { PollingThread.new(@model_queue, @stop_flag, logger, @executor) }
      polling_threads.each(&:run)
      polling_threads.each(&:join)

      @executor.shutdown
      @executor.wait_for_termination
    end

    def stop
      @stop_flag.set!
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
crono_trigger-0.3.2 lib/crono_trigger/worker.rb
crono_trigger-0.3.0 lib/crono_trigger/worker.rb
crono_trigger-0.2.0 lib/crono_trigger/worker.rb
crono_trigger-0.1.0 lib/crono_trigger/worker.rb
crono_trigger-0.0.1 lib/crono_trigger/worker.rb