class Serverkit::Actions::Apply

Public Instance Methods

run() click to toggle source

Apply recipe so that all backends have ideal states, then exit with 0 or 1

# File lib/serverkit/actions/apply.rb, line 7
def run
  if apply_resources
    exit
  else
    exit(1)
  end
end

Private Instance Methods

apply_resources() click to toggle source

@return [true, false] True if all backends have ideal states

# File lib/serverkit/actions/apply.rb, line 18
def apply_resources
  backends.map do |backend|
    Thread.new do
      resources = recipe.resources.map(&:clone).map do |resource|
        resource.backend = backend
        resource.run_apply
        backend.logger.report_apply_result_of(resource)
        resource
      end
      handlers = resources.select(&:notifiable?).flat_map(&:handlers).uniq.map(&:clone).each do |handler|
        handler.backend = backend
        handler.run_apply
        backend.logger.report_apply_result_of(handler)
      end
      resources + handlers
    end
  end.map(&:value).flatten.all?(&:successful?)
end