@@ -27,16 +27,33 @@ def __str__(self):
2727 return "{}-{}" .format (self .app .id , str (self .uuid )[:7 ])
2828
2929 def healthcheck (self ):
30- # Update healthcheck - Scheduler determines the app type
30+ """
31+ Get all healthchecks options together for use in scheduler
32+ """
33+ # return empty dict if no healthcheck is found
3134 if 'HEALTHCHECK_URL' not in self .values .keys ():
3235 return {}
36+
3337 path = self .values .get ('HEALTHCHECK_URL' , '/' )
3438 timeout = int (self .values .get ('HEALTHCHECK_TIMEOUT' , 50 ))
3539 delay = int (self .values .get ('HEALTHCHECK_INITIAL_DELAY' , 50 ))
36- port = int (self .values .get ('HEALTHCHECK_PORT' , 8080 ))
40+ port = int (self .values .get ('HEALTHCHECK_PORT' , 5000 ))
3741
3842 return {'path' : path , 'timeout' : timeout , 'delay' : delay , 'port' : port }
3943
44+ def set_healthchecks (self ):
45+ """Defines default values for HTTP healthchecks"""
46+ if not {k : v for k , v in self .values .items () if k .startswith ('HEALTHCHECK_' )}:
47+ return
48+
49+ # fetch set health values and any defaults
50+ # this approach allows new health items to be added without issues
51+ health = self .healthcheck ()
52+ self .values ['HEALTHCHECK_URL' ] = health ['path' ]
53+ self .values ['HEALTHCHECK_TIMEOUT' ] = health ['timeout' ]
54+ self .values ['HEALTHCHECK_INITIAL_DELAY' ] = health ['delay' ]
55+ self .values ['HEALTHCHECK_PORT' ] = health ['port' ]
56+
4057 def save (self , ** kwargs ):
4158 """merge the old config with the new"""
4259 try :
@@ -61,6 +78,9 @@ def save(self, **kwargs):
6178 except Config .DoesNotExist :
6279 pass
6380
81+ # set any missing HEALTHCHECK_* elements
82+ self .set_healthchecks ()
83+
6484 # verify the tags exist on any nodes as labels
6585 if self .tags :
6686 # Get all nodes with label selectors
0 commit comments