Hi partners,
I am trying to do a deployment and I need to stop the deploy
recipe when deployment is successful. I use a function called isReachable?(url)
which belong to the Tools
module. This function return true if the url is reachable. I only can use the above function within ruby_block because in compile time give me a error. Then, I use this function to determinate if app is ready and it work fine. The problem is when I try to stop processing the deploy
recipe with the following code:
3.times do |i|
#Code for deployment....
# Ruby code to verify the deployment of App
ruby_block 'verify deployment' do
block do
if Tools.isReachable?('http://localhost:8080/App')
Chef::Log.info($message)
Tools.send_email mail_from, mail_to, :message => $message
return
else
Chef::Log.warn("App deployment failed (#{i + 1}/3)")
end
end
end
end
The function’s code (only for information):
def self.isReachable?(url)
require 'mechanize'
sw = true
agent = Mechanize.new
agent.user_agent_alias = 'Windows Chrome'
agent.agent.http.verify_mode = OpenSSL::SSL::VERIFY_NONE
begin
agent.read_timeout = 5 #set the agent time out
page = agent.get(url)
agent.history.pop() #delete this request in the history
rescue Mechanize::ResponseCodeError
sw = false
end
return sw
end
the code of default
recipe:
# System preconfigurations
include_recipe 'deploy_war::prepare'
# Deploy
include_recipe 'deploy_war::deploy'
# Task Scheduler
include_recipe 'deploy_war::task_scheduler'
I use return
because of I was reading about how solve my problem but I get this error:
#<LocalJumpError: ruby_block[verify deployment] (deploy_war::deploy_proc line 87) had an error: LocalJumpError: unexpected return> had an error:
ruby_block[verify deployment] (deploy_war::deploy_proc line 87) had an error: LocalJumpError: unexpected return
Any help ?