Class: Berkshelf::API::CacheBuilder

Inherits:
Object
  • Object
show all
Includes:
GenericServer, Logging, Mixin::Services
Defined in:
lib/berkshelf/api/cache_builder.rb,
lib/berkshelf/api/cache_builder/worker.rb,
lib/berkshelf/api/cache_builder/worker/github.rb,
lib/berkshelf/api/cache_builder/worker/opscode.rb,
lib/berkshelf/api/cache_builder/worker/file_store.rb,
lib/berkshelf/api/cache_builder/worker/chef_server.rb

Defined Under Namespace

Modules: Worker Classes: WorkerSupervisor

Constant Summary collapse

BUILD_INTERVAL =
5.0

Instance Method Summary collapse

Methods included from Mixin::Services

extended, included

Methods included from Logging

init, #logger

Methods included from GenericServer

included

Constructor Details

#initializeCacheBuilder

Returns a new instance of CacheBuilder.



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/berkshelf/api/cache_builder.rb', line 16

def initialize
  log.info "Cache Builder starting..."
  @worker_registry   = Celluloid::Registry.new
  @worker_supervisor = WorkerSupervisor.new(@worker_registry)
  @building          = false

  Application.config.endpoints.each_with_index do |endpoint, index|
    endpoint_options = endpoint.options.to_hash.deep_symbolize_keys
    @worker_supervisor.supervise(CacheBuilder::Worker[endpoint.type], endpoint_options.merge(priority: index))
  end
end

Instance Method Details

#buildObject



28
29
30
# File 'lib/berkshelf/api/cache_builder.rb', line 28

def build
  cache_manager.process_workers(workers)
end

#build_loop(interval = BUILD_INTERVAL) ⇒ Object

Issue a build command to all workers at the scheduled interval

Parameters:

  • interval (Fixnum, Float) (defaults to: BUILD_INTERVAL)


35
36
37
38
39
40
41
42
43
# File 'lib/berkshelf/api/cache_builder.rb', line 35

def build_loop(interval = BUILD_INTERVAL)
  return if @building

  loop do
    @building = true
    build
    sleep interval
  end
end

#workersArray<CacheBuilder::Worker::Base>

Return the list of running workers

Returns:



48
49
50
# File 'lib/berkshelf/api/cache_builder.rb', line 48

def workers
  @worker_supervisor.actors
end