Sha256: 63cda0e94932873793574c83ff7481adc9f0fbf59f194267cdcc1b7e15e138c7

Contents?: true

Size: 902 Bytes

Versions: 1

Compression:

Stored size: 902 Bytes

Contents

module Sidetiq
  # Public: Mixin for Sidekiq::Worker classes.
  #
  # Examples
  #
  #   class MyWorker
  #       include Sidekiq::Worker
  #       include Sidetiq::Schedulable
  #
  #       # Daily at midnight
  #       tiq { daily }
  #     end
  module Schedulable
    module ClassMethods
      def last_scheduled_occurrence
        get_timestamp "last"
      end

      def next_scheduled_occurrence
        get_timestamp "next"
      end

      def tiq(&block) # :nodoc:
        clock = Sidetiq::Clock.instance
        clock.synchronize do
          clock.schedule_for(self).instance_eval(&block)
        end
      end

    private

      def get_timestamp(key)
        Sidekiq.redis do |redis|
          (redis.get("sidetiq:#{name}:#{key}") || -1).to_f
        end
      end
    end

    def self.included(klass) # :nodoc:
      klass.extend(Sidetiq::Schedulable::ClassMethods)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sidetiq-0.2.0 lib/sidetiq/schedulable.rb