Skip to content

Commit a325374

Browse files
committed
bit more refactoring
1 parent 25cebdd commit a325374

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

job-utilities/job_router/lambda_function.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,24 @@ def handler(event, _):
2121
CMR_LB_NAME - The LB used for routing calls to CMR
2222
"""
2323
environment = os.getenv('CMR_ENVIRONMENT')
24-
cmr_lb_name = os.getenv('CMR_LB_NAME')
2524

26-
if environment is None:
25+
if not environment:
2726
print("ERROR: CMR_ENVIRONMENT variable not set!")
28-
if cmr_lb_name is None:
27+
if not os.getenv("CMR_LB_NAME"):
2928
print("ERROR: CMR_LB_NAME variable not set!")
30-
if environment is None or cmr_lb_name is None:
29+
if environment is None or os.getenv("CMR_LB_NAME") is None:
3130
sys.exit(1)
3231

3332
if environment == 'local':
3433
route_local(event=event)
3534
else:
36-
route(host=cmr_lb_name, environment=environment, event=event)
35+
route(environment=environment, event=event)
3736

3837
def send_request(request_type, token, url):
38+
"""
39+
Sends the request of given type with given token
40+
to given url
41+
"""
3942
timeout = int(os.getenv('ROUTER_TIMEOUT', '300'))
4043

4144
pool_manager = urllib3.PoolManager(headers={"Authorization": token, \
@@ -49,6 +52,9 @@ def send_request(request_type, token, url):
4952
sys.exit(-1)
5053

5154
def route_local(event):
55+
"""
56+
Handles the routing for a local request
57+
"""
5258
service = event.get('service', 'bootstrap')
5359
endpoint = event.get('endpoint')
5460
request_type = event.get('request-type', "GET")
@@ -68,7 +74,12 @@ def route_local(event):
6874
print(e)
6975
sys.exit(-1)
7076

71-
def route(host, environment, event):
77+
def route(environment, event):
78+
"""
79+
Handles routing for single target and multi target requests
80+
on a deployed environment
81+
"""
82+
host = os.getenv('CMR_LB_NAME')
7283
service = event.get('service', 'bootstrap')
7384
endpoint = event.get('endpoint')
7485
single_target = event.get('single-target', True)

0 commit comments

Comments
 (0)