We made significant progress by creating upper and lower limit for scaling. From now on, the script will not exceed them. However, the fact that we will stay within those limit does not mean that the problem that initiated the procedure is gone. Whichever process decided that a service should be scaled probably did that based on some metrics. If, for example, the average response time was slow and the system failed to scale up, the problem will persist unless there is some dark magic involved. We can categorize this situation as "the body tried to self-adapt, it failed, it's time to consult a doctor." Since we live in the 21st century, we won't call him but send him a Slack message.
Before we proceed and modify the script one more time, we need to configure Slack in Jenkins:
open "http://$(docker-machine ip swarm-1...