-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from HumanCellAtlas/FT-GH-675-FlaconLivenessFix
Ft gh 675 flacon liveness fix
- Loading branch information
Showing
7 changed files
with
152 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -137,3 +137,6 @@ Icon | |
Network Trash Folder | ||
Temporary Items | ||
.apdisk | ||
|
||
##JetBrain Stuff | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,35 @@ | ||
import json | ||
import threading | ||
from datetime import datetime, timedelta | ||
import os | ||
from flask import abort | ||
|
||
FALCON_THREAD_NAMES = ('queueHandler', 'igniter') | ||
from flask import render_template | ||
from falcon.settings import docRootPath, docRootFile, MAX_DELAY | ||
|
||
|
||
def status(): | ||
active_threads = {thread.name: thread for thread in threading.enumerate()} | ||
active_falcon_threads = {} | ||
for falcon_thread_name in FALCON_THREAD_NAMES: | ||
thread = active_threads.get(falcon_thread_name) | ||
if not thread: | ||
abort(500) | ||
elif not thread.is_alive(): | ||
abort(500) | ||
""" | ||
This function reads a status report file creation date and | ||
Compares it to the current time | ||
Returns: render html file or abort (HTTP code 500) if time | ||
difference is greater than max delay | ||
""" | ||
|
||
try: | ||
# Get TimeStamp | ||
now = datetime.today() | ||
|
||
# read status report.html modified datetime | ||
file_mod_time = datetime.fromtimestamp( | ||
os.stat(docRootPath + docRootFile).st_mtime | ||
) # This is a datetime.datetime object! | ||
|
||
# Define max delay to 5 mins | ||
max_delay = timedelta(minutes=MAX_DELAY) | ||
|
||
# if reached max delay abort else render status report file | ||
if now - file_mod_time > max_delay: | ||
abort(500, 'reached max delay') | ||
else: | ||
display_name = '{}-thread'.format(falcon_thread_name) | ||
active_falcon_threads[display_name] = str(thread.ident) | ||
return json.dumps(active_falcon_threads) | ||
return render_template(docRootFile) | ||
|
||
except Exception as exc: | ||
abort(500, exc) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<html> | ||
<head></head> | ||
<body><p> Timestamp should be Here | ||
############### NOTES ##################### | ||
For some caching issue it might not show up | ||
Running : Curl -I http://localhost:8000/health | ||
Result should confirm cache headers are correct (no-cache, etc) | ||
checking the content of the file on he disk should confirm this is a cache issue | ||
cat /falcon/templates/handler_status.html | ||
########################################### | ||
</p></body> | ||
</html> |