Sha256: b69b5f5b03d290455ab345ee88befb32d28fd7a647485bd9331ddf99a74534ac

Contents?: true

Size: 949 Bytes

Versions: 3

Compression:

Stored size: 949 Bytes

Contents

module Proletariat
  # Public: Sets up a supervisor which maintains a single Publisher and a
  # per-worker Manager instance.
  class Runner
    extend Forwardable

    # Public: Start the workers.
    #
    # Returns nil.
    def run
      @managers = Proletariat.worker_classes.map do |worker_class|
        Manager.spawn!(name: "manager_#{worker_class.to_s}_#{object_id}",
                       supervise: true,
                       args: [worker_class])
      end

      managers.each { |manager| manager << :run }

      nil
    end

    # Public: Check whether the workers are currently running.
    def running?
      !!managers
    end

    # Public: Stop the workers.
    #
    # Returns nil.
    def stop
      managers.each { |manager| manager << :terminate! } if managers
      @managers = nil

      nil
    end

    private

    # Internal: Returns an Array of the currently supervised Managers.
    attr_reader :managers
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
proletariat-0.1.2 lib/proletariat/runner.rb
proletariat-0.1.1 lib/proletariat/runner.rb
proletariat-0.1.0 lib/proletariat/runner.rb