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/file_store.rb,
lib/berkshelf/api/cache_builder/worker/chef_server.rb,
lib/berkshelf/api/cache_builder/worker/supermarket.rb

Defined Under Namespace

Modules: Worker Classes: WorkerSupervisor

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.



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

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

  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



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

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)


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

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:



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

def workers
  @worker_supervisor.actors
end