Skip to content

Commit

Permalink
Merge branch 'dev' into prod
Browse files Browse the repository at this point in the history
  • Loading branch information
Genarito committed Oct 13, 2023
2 parents 4fd4302 + d5b78a6 commit dadd321
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 18 deletions.
5 changes: 4 additions & 1 deletion docker-compose_dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ services:
# Hosts separated by comma ('http://', 'https://' prefixes are mandatory)
# Example: CSRF_TRUSTED_ORIGINS: 'http://127.0.0.1', 'http://127.0.0.1,https://127.0.0.1:8000', etc
CSRF_TRUSTED_ORIGINS: 'http://modulector:8000,http://www.modulector:8000'
ALLOWED_HOSTS: 'modulector'

# Allowed host must include the ones set in the NGINX modulector.conf file. Localhost is included for
# health-checks
ALLOWED_HOSTS: 'web,modulector,localhost'

volumes:
postgres_data:
Expand Down
41 changes: 24 additions & 17 deletions tools/healthcheck/check.py
Original file line number Diff line number Diff line change
@@ -1,47 +1,54 @@
import requests,sys, os
import requests, sys, os


def check():
exit_code = os.EX_OK
health_url = os.getenv("HEALTH_URL","http://localhost:8000/drugs/")
health_url = os.getenv("HEALTH_URL", "http://localhost:8000/drugs/")
try:
r = requests.get(health_url)
if r.status_code != 200 :
if r.status_code != 200:
raise Exception("The probe has failed")
set_tries("0")
except:
except Exception as ex:
print(ex)
notify()
exit_code = os.EX_SOFTWARE
sys.exit(exit_code)


def notify():
url = os.getenv("HEALTH_ALERT_URL","")
if url!="":
url = os.getenv("HEALTH_ALERT_URL", "")
if url != "":
tries = get_tries()
tries = tries+1
tries = tries + 1
headers = {'Content-Type': 'application/json'}
message="Modulector: Health check failed {} times.".format(tries)
if tries==3:
message = "Modulector: Health check failed {} times.".format(tries)
if tries == 3:
message = message + " The container has been marked as unhealthy."
set_tries(0)
data = { "content": message }
data = {"content": message}
try:
r = requests.post(url,headers=headers, json=data)
except:
requests.post(url, headers=headers, json=data)
except Exception as ex:
print(ex)
pass
set_tries(str(tries))


def get_tries():
tries=0
tries = 0
try:
with open("tries.txt","r") as f:
tries=f.read()
with open("tries.txt", "r") as f:
tries = f.read()
except FileNotFoundError:
set_tries(0)
return int(tries)


def set_tries(tries):
with open("tries.txt","w") as f:
with open("tries.txt", "w") as f:
f.write(str(tries))

if __name__=="__main__":

if __name__ == "__main__":
check()

0 comments on commit dadd321

Please sign in to comment.