/usr/lib/ruby/vendor_ruby/berkshelf/api/cache_builder.rb is in berkshelf-api 2.2.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | module Berkshelf::API
class CacheBuilder
require_relative 'cache_builder/worker'
class WorkerSupervisor < Celluloid::SupervisionGroup; end
include Berkshelf::API::GenericServer
include Berkshelf::API::Logging
include Berkshelf::API::Mixin::Services
server_name :cache_builder
finalizer :finalize_callback
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
def build
cache_manager.process_workers(workers)
end
# Issue a build command to all workers at the scheduled interval
#
# @param [Fixnum, Float] interval
def build_loop(interval = @build_interval)
return if @building
loop do
@building = true
build
sleep interval
end
end
# Return the list of running workers
#
# @return [Array<CacheBuilder::Worker::Base>]
def workers
@worker_supervisor.actors
end
private
def finalize_callback
log.info "Cache Builder shutting down..."
@worker_supervisor.terminate if @worker_supervisor && @worker_supervisor.alive?
end
end
end
|