class CacheJSON::Worker

Public Instance Methods

perform(params="{}") click to toggle source
# File lib/cache_json/worker.rb, line 20
def perform(params="{}")
  parsed_params = JSON.parse(params)
  klass = parsed_params["klass"]
  args = (parsed_params["args"] || {}).transform_keys(&:to_sym)
  if klass
    klass = Object.const_get(klass)
    klass.new.refresh_cache!(args: args) if should_refresh?(klass, args)
  else
    AllPermutations.new.results.each do |perm|
      if should_refresh?(perm[:klass], perm[:args])
        perm[:klass] = perm[:klass].to_s
        CacheJSON::Worker.perform_async(perm.to_json)
      end
    end
  end
end
perform_async(*) click to toggle source
# File lib/cache_json/worker.rb, line 14
def perform_async(*)
  raise 'Sidekiq gem not found. ' \
        'You can still call this worker manually via CacheJSON::Worker.new.perform'
end

Private Instance Methods

should_refresh?(klass, args) click to toggle source
# File lib/cache_json/worker.rb, line 39
def should_refresh?(klass, args)
  !klass.new.check_cache(args: args) || klass.new.cache_expiring_soon?(args: args)
end