-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy path__init__.py
More file actions
48 lines (39 loc) · 1.49 KB
/
__init__.py
File metadata and controls
48 lines (39 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
"""
Code to poll for realtime changes
"""
import os
import aikido_zen.background_process.requests as requests
from aikido_zen.helpers.logging import logger
from aikido_zen.helpers.urls.get_api_url import get_api_url
def get_realtime_url():
"""Fetches the default realtime url or environment variable"""
realtime_url = os.getenv("AIKIDO_REALTIME_ENDPOINT")
if realtime_url is not None:
if not realtime_url.endswith("/"):
realtime_url += "/"
return realtime_url
return "https://runtime.aikido.dev/"
def get_config(token):
"""Fetches the config from realtime URL"""
url = get_api_url() + "api/runtime/config"
headers = {
"Authorization": str(token),
}
response = requests.get(url, headers=headers, timeout=3) # timeout in 3 seconds
if response.status_code != 200:
logger.info("Invalid response from api : %s", response.status_code)
return response.json() # Parse and return the JSON response
def get_config_last_updated_at(token):
"""
Fetches the time when the config was last updated from realtime server
"""
url = f"{get_realtime_url()}config"
headers = {
"Authorization": str(token),
}
response = requests.get(url, headers=headers, timeout=0.5) # timeout in 500ms
if response.status_code != 200:
logger.info("Invalid response from realtime api : %s", response.status_code)
return int(
response.json().get("configUpdatedAt", 0)
) # Return configUpdatedAt time