Sha256: 3d88be75be13922f9a848944f474679e8b52f7f7cacf465bcd3f1f93acf4c05a

Contents?: true

Size: 747 Bytes

Versions: 5

Compression:

Stored size: 747 Bytes

Contents

module FistOfFury
  class Dispatcher
    include Logging

    def dispatch(worker, time)
      worker.schedule_next(time) do
        enqueue(worker, worker.next_scheduled_occurrence)
      end
    rescue StandardError => e
      # TODO: exception handling support
      raise e
    end

    protected

    def enqueue(worker, next_run_time)
      klass = worker.to_s
      info "Enqueue: #{klass}"
      last_run_time = FistOfFury.store["#{klass}:next"] || -1
      next_run_time = next_run_time.to_f
      FistOfFury.store["#{klass}:last"] = last_run_time
      FistOfFury.store["#{klass}:next"] = next_run_time
      worker.new.async.perform
    rescue StandardError => e
      # TODO: exception handling support
      raise e
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
fist_of_fury-0.2.7 lib/fist_of_fury/dispatcher.rb
fist_of_fury-0.2.6 lib/fist_of_fury/dispatcher.rb
fist_of_fury-0.2.5 lib/fist_of_fury/dispatcher.rb
fist_of_fury-0.2.1 lib/fist_of_fury/dispatcher.rb
fist_of_fury-0.2.0 lib/fist_of_fury/dispatcher.rb