-
Notifications
You must be signed in to change notification settings - Fork 0
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 #63 from CanDIG/feature/safe-check
Add the ability to send requests with "safe" checking, exiting early if the service info cannot be quickly communicated with
- Loading branch information
Showing
4 changed files
with
64 additions
and
6 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
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,44 @@ | ||
#!/usr/bin/env python3 | ||
import time | ||
from network import get_registered_servers | ||
import requests | ||
import os.path | ||
|
||
def check_pulse(): | ||
servers = get_registered_servers() | ||
if len(servers) == 0: | ||
return | ||
# Determine which sites we have access to | ||
live_servers = [] | ||
log = "" | ||
try: | ||
for server in servers.values(): | ||
url = f"{server['server']['url']}/v1/service-info" | ||
log += f"\ntesting {url}" | ||
service_info = requests.get(url, timeout=2) | ||
if service_info.ok: | ||
live_servers.append(server['server']['id']) | ||
|
||
# Determine whether or not those sites are available by pinging Federation service-info | ||
with open('/app/federation/live_servers.txt', 'w') as f: | ||
f.write("|".join(live_servers)) | ||
except Exception as e: | ||
log += "\n" + str(e) | ||
|
||
with open('/app/federation/log.txt', 'w') as f: | ||
f.write(log) | ||
f.write(str(e)) | ||
|
||
|
||
def get_live_servers(): | ||
live_servers = [] | ||
if os.path.isfile("/app/federation/live_servers.txt"): | ||
with open('/app/federation/live_servers.txt', 'r') as f: | ||
live_servers_str = f.read().strip() | ||
live_servers = live_servers_str.split('|') | ||
return live_servers | ||
|
||
if __name__ == "__main__": | ||
while(True): | ||
check_pulse() | ||
time.sleep(30) |
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