lib/harbr/next/job.rb in harbr-0.1.39 vs lib/harbr/next/job.rb in harbr-0.1.41
- old
+ new
@@ -6,10 +6,27 @@
module Harbr
module Next
class Job
include SuckerPunch::Job
+
+ def check
+ sleep_times = [1, 3, 5, 8, 23]
+ begin
+ result = yield if block_given?
+ unless result
+ sleep_times.each do |time|
+ result = yield if block_given?
+ break if result
+ sleep(time)
+ end
+ end
+ rescue => e
+ puts "Error: #{e.message}"
+ end
+ end
+
def get_container_name(path)
File.basename(path)
end
def create_traefik_config(containers)
@@ -161,15 +178,36 @@
raise "Manifest not found at #{manifest_path}" unless File.exist?(manifest_path)
manifest_data = YAML.load_file(manifest_path)
OpenStruct.new(manifest_data)
end
+ def check
+ sleep_times = [1, 3, 5, 8, 23]
+ begin
+ result = yield if block_given?
+ unless result
+ sleep_times.each do |time|
+ result = yield if block_given?
+ break if result
+ sleep(time)
+ end
+ end
+ rescue => e
+ puts "Error: #{e.message}"
+ end
+ end
+
def perform(name, version)
Harbr.notifiable(name, version) do
manifest = load_manifest(name, version)
current_path = "/var/harbr/containers/#{name}/versions/#{version}"
port = `port assign next.#{manifest.port}`.strip
+
+ check do
+ puts "Waiting for container #{current_path} 5to be available..."
+ Dir.exist?(current_path)
+ end
Dir.chdir current_path do
system "sv stop next.#{name}"
if File.exist?("Gemfile")
`bundle config set --local path 'vendor/bundle'`