class Mamiya::Agent::Tasks::Switch
Public Instance Methods
check()
click to toggle source
# File lib/mamiya/agent/tasks/switch.rb, line 17 def check return true if ignore_incompletion? && (prerelease_path.exist? || release_path.exist?) return true if prerelease_prepared? return true if release_prepared? unless package_path.exist? new_chain = ['prepare', 'switch'] + (task['_chain'] || []) logger.info "Package not fetched, enqueueing fetch task with #{new_chain.inspect}" task_queue.enqueue( :fetch, task.merge('_chain' => new_chain) ) return false end unless prerelease_prepared? new_chain = ['switch'] + (task['_chain'] || []) logger.info "Package not prepared, enqueueing prepare task with #{new_chain.inspect}" task_queue.enqueue( :prepare, task.merge('_chain' => new_chain) ) return false end true end
execute()
click to toggle source
Calls superclass method
Mamiya::Agent::Tasks::Notifyable#execute
# File lib/mamiya/agent/tasks/switch.rb, line 12 def execute return unless check super end
run()
click to toggle source
# File lib/mamiya/agent/tasks/switch.rb, line 45 def run case when prerelease_prepared? && release_path.exist? && !release_path.join('.mamiya.prepared').exist? logger.info "Removing existing release (not prepared)" FileUtils.remove_entry_secure release_path when ignore_incompletion? && (prerelease_path.exist? || release_path.exist?) logger.warn "Using incomplete release or prereleases" when !prerelease_prepared? && prerelease_path.exist? && !release_path.join('.mamiya.prepared').exist? # this condition may be a bug logger.error "Existing release is not prepared but prerelease doesn't exist" raise PrereleaseMissing, "Existing release is not prepared but prerelease doesn't exist" end unless release_path.exist? logger.info "Copying #{prerelease_path} -> #{release_path}" FileUtils.cp_r prerelease_path, release_path end logger.info "Switching" switch_step.run! task_queue.enqueue(:clean, {}) end
Private Instance Methods
application()
click to toggle source
# File lib/mamiya/agent/tasks/switch.rb, line 71 def application task['app'] end
ignore_incompletion?()
click to toggle source
# File lib/mamiya/agent/tasks/switch.rb, line 79 def ignore_incompletion? task['allow_incomplete'] || task['allow_incompletion'] || task['incomplete'] end
labels()
click to toggle source
# File lib/mamiya/agent/tasks/switch.rb, line 119 def labels @labels ||= agent.labels end
package()
click to toggle source
# File lib/mamiya/agent/tasks/switch.rb, line 75 def package task['pkg'] end
package_path()
click to toggle source
# File lib/mamiya/agent/tasks/switch.rb, line 95 def package_path packages_dir.join(application, "#{package}.tar.gz") end
packages_dir()
click to toggle source
# File lib/mamiya/agent/tasks/switch.rb, line 87 def packages_dir @packages_dir ||= config.packages_dir end
prerelease_path()
click to toggle source
# File lib/mamiya/agent/tasks/switch.rb, line 99 def prerelease_path prereleases_dir.join(application, release_name) end
prerelease_prepared?()
click to toggle source
# File lib/mamiya/agent/tasks/switch.rb, line 115 def prerelease_prepared? prerelease_path.exist? && prerelease_path.join('.mamiya.prepared').exist? end
prereleases_dir()
click to toggle source
# File lib/mamiya/agent/tasks/switch.rb, line 91 def prereleases_dir @prereleases_dir ||= config.prereleases_dir end
release_name()
click to toggle source
# File lib/mamiya/agent/tasks/switch.rb, line 83 def release_name task['release'] || package end
release_path()
click to toggle source
# File lib/mamiya/agent/tasks/switch.rb, line 107 def release_path releases_dir.join(release_name) end
release_prepared?()
click to toggle source
# File lib/mamiya/agent/tasks/switch.rb, line 111 def release_prepared? release_path.exist? && release_path.join('.mamiya.prepared').exist? end
releases_dir()
click to toggle source
# File lib/mamiya/agent/tasks/switch.rb, line 103 def releases_dir config.deploy_to_for(application).join('releases').tap(&:mkpath) end
switch_step()
click to toggle source
# File lib/mamiya/agent/tasks/switch.rb, line 123 def switch_step @switch_step ||= Mamiya::Steps::Switch.new( target: release_path, config: config, logger: logger, labels: agent.labels, no_release: !!task['no_release'], do_release: !!task['do_release'], ) end