Sha256: b0225d9f76d9a1221de0598abd072ebda82b6b942215dda3b48d1f37eb37a024

Contents?: true

Size: 881 Bytes

Versions: 1

Compression:

Stored size: 881 Bytes

Contents

module Resque
  class SettingNotFound < RuntimeError; end

  class ThrottledJob

    THROTTLE_DEFAULTS = {
        :can_run_every => 1800,
        :enqueued      => 'Your job has been submitted. You will receive an email with a download link shortly.',
        :throttled     => 'Frequency has been exceeded. Job not submitted. Try again a little later.',
        :latest        => 'Download the most recent result',
        :disabled      => false,
        :identifier    => nil
    }

    def self.settings
      @settings ||= THROTTLE_DEFAULTS.dup
    end

    def self.throttle(args = {})
      settings.merge!(args)
    end

    def self.key
      [self.to_s, identifier].compact.join(":")
    end

    def self.method_missing(method, *args)
      raise SettingNotFound("Could not find the #{method} setting") if !settings.key?(method)
      settings[method]
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
resque-throttle-0.2.4 lib/resque/throttled_job.rb