Class: CacheJSON::Worker

Inherits:
Object
  • Object
show all
Includes:
Sidekiq::Worker
Defined in:
lib/cache_json/worker.rb

Defined Under Namespace

Classes: AllPermutations

Instance Method Summary collapse

Instance Method Details

#perform(params = "{}") ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# 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_asyncObject



14
15
16
17
# 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