Sha256: 43a4cd49c01fecbbd0d43046ca777314e8935bfd207fb1ad59514abe28cba33c

Contents?: true

Size: 822 Bytes

Versions: 1

Compression:

Stored size: 822 Bytes

Contents

require "snowman-io/processor"

module SnowmanIO
  # Scheduler schedules execution of checks.
  class Scheduler
    include Celluloid
    trap_exit :processor_died

    attr_accessor :handler

    def initialize(checks)
      @time = {}
      checks.each do |check|
        @time[check] = Time.now + check.interval
      end
    end

    def start
      every(1) { schedule_checks }
    end

    def processor_done(processor, result)
      @handler.async.handle(result)
      processor.terminate
    end

    private

    def schedule_checks
      @time.each do |check, time|
        if time <= Time.now
          Processor.new_link(current_actor).async.process(check)
          @time[check] = Time.now + check.interval
        end
      end
    end

    def processor_died(_actor, _reason)
      # TODO
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
snowman-io-0.0.4 lib/snowman-io/scheduler.rb