Some background. I want to delete AWS Redshift cluster and the process takes more than 30 minute. So this is what I want to do:
- Start the deletion
- Every 1 minute, check the cluster status (it should be “deleting”)
- When the cluster is deleted, the command would fail (because it cannot find the cluster anymore). So log some message and continue with rest of the script
This is the command I run in a while
loop to check the cluster status after I start the deletion:
resp = redshift.client.describe_clusters(:cluster_identifier=>"blahblahblah")
Above command will get me cluster status as deleting
while the deletion process continues. But once the cluster is completely deleted, then the command itself will fail as it cannot find the cluster blahblahblah
.
Here is the error from command once the cluster is deleted:
/var/lib/gems/1.9.1/gems/aws-sdk-1.14.1/lib/aws/core/client.rb:366:in `return_or_raise': Cluster blahblahblah not found. (AWS::Redshift::Errors::ClusterNotFound)
I agree with this error. But this makes my script exit abruptly. So I want to log a message saying The cluster is deleted....continuing
and continue with my script.
I tried below settings
resp = redshift.client.describe_clusters(:cluster_identifier=>"blahblahblah")
|| raise (“The cluster is deleted....continuing”)
I also tried couple of suggestion mentioned at https://www.ruby-forum.com/topic/133876 But this is not working. My script exits once above command fails to find the cluster.
Questions: How to ignore the error, print my own message saying “The cluster is deleted....continuing” and continue with the script ?
Thanks.
@NewAlexandria, I changed your code to look like below:
OUTPUT:
I changed the
raise
toputs
in the line that immediately follows therescue
line in your response. This way I got rid of theRuntimeError
that I mentioned in my comment above.I do not know what are the implication of this. I do not even know whether this is the right way to do it. But It shows the error when the cluster is not found and then continues with the script.
Later I read a lot of articles on ruby
exception/rescue/raise/throw
.... but that was just too much for me to understand as I do not belong to programming background at all. So, if you could explain what is going on here, it will really helpful for me to get more confidence in ruby.Thanks for your time.