Sha256: 1589114febe2ee328ac94a377c7a7fe90a9a98e9f2f0393454fe1c8837e4addc

Contents?: true

Size: 1.34 KB

Versions: 8

Compression:

Stored size: 1.34 KB

Contents

module Sidetiq
  # Public: The Sidetiq clock.
  class Clock
    include Logging

    def self.start!
      warn "Sidetiq::Clock#start! is deprecated. Calling it is no longer required."
    end

    def start!
      warn "Sidetiq::Clock#start! is deprecated. Calling it is no longer required."
    end

    # Internal: Returns a hash of Sidetiq::Schedule instances.
    attr_reader :schedules

    def initialize # :nodoc:
      super
    end

    # Public: Get the schedule for `worker`.
    #
    # worker - A Sidekiq::Worker class
    #
    # Examples
    #
    #   schedule_for(MyWorker)
    #   # => Sidetiq::Schedule
    #
    # Returns a Sidetiq::Schedule instances.
    def schedule_for(worker)
      if worker.respond_to?(:schedule)
        worker.schedule
      end
    end

    # Public: Issue a single clock tick.
    #
    # Examples
    #
    #   tick
    #   # => Hash of Sidetiq::Schedule objects
    #
    # Returns a hash of Sidetiq::Schedule instances.
    def tick(tick = gettime)
      Sidetiq.workers.each do |worker|
        Sidetiq.handler.dispatch(worker, tick)
      end
    end

    # Public: Returns the current time used by the clock.
    #
    # Examples
    #
    #   gettime
    #   # => 2013-02-04 12:00:45 +0000
    #
    # Returns a Time instance.
    def gettime
      Sidetiq.config.utc ? Time.now.utc : Time.now
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
sidetiq-0.6.3 lib/sidetiq/clock.rb
sidetiq-0.6.2 lib/sidetiq/clock.rb
sidetiq-0.6.1 lib/sidetiq/clock.rb
sidetiq-0.6.0 lib/sidetiq/clock.rb
sidetiq-0.5.0 lib/sidetiq/clock.rb
sidetiq-0.4.3 lib/sidetiq/clock.rb
sidetiq-0.4.2 lib/sidetiq/clock.rb
sidetiq-0.4.1 lib/sidetiq/clock.rb