Module: WarmingDrawer

Defined in:
lib/warming_drawer.rb,
lib/warming_drawer/version.rb,
lib/warming_drawer/configuration.rb,
lib/warming_drawer/workers/url_worker.rb,
lib/warming_drawer/workers/base_worker.rb

Defined Under Namespace

Modules: Workers Classes: Configuration

Constant Summary collapse

VERSION =
"0.0.3"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configurationObject

Returns the value of attribute configuration.



9
10
11
# File 'lib/warming_drawer.rb', line 9

def configuration
  @configuration
end

Class Method Details

.configure {|configuration| ... } ⇒ Object

Yields:



12
13
14
15
# File 'lib/warming_drawer.rb', line 12

def self.configure
  self.configuration ||= Configuration.new
  yield(configuration)
end

.use_queue?Boolean

Returns true if a queuing system is defined

Returns:

  • (Boolean)


46
47
48
# File 'lib/warming_drawer.rb', line 46

def self.use_queue?
  configuration.queue_system != :inline
end

.warm(*args) ⇒ Boolean

Warms a cache. Delegates to the proper worker depending on the type. If being used within Rails, returns false unless action_controller caching is enabled.

Examples:

WarmingDrawer.warm('http://sweet.dev/1', 'http://sweet2.dev/2', :type => :url)
=> true

Parameters:

  • args (Array)

    Arguments or Array to warm

Returns:

  • (Boolean)


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/warming_drawer.rb', line 25

def self.warm(*args)
  return false unless cachable?

  if args.last.is_a?(Hash)
    options = args.pop
  else
    options = {}
  end
  options[:type] ||= :url

  if worker = available_worker_for_type(options[:type])
    # TODO: can this move into worker since its reading config?
    worker.options queue: configuration.queue_name, retry: configuration.retry
    worker.perform_with(args)
  end

  !worker.nil?
end