in source/core-api/lambda_functions/generate_events.py [0:0]
def lambda_handler(event, context):
"""
This function is the entry handler for Lambda.
"""
print(event)
input_params = {"queryStringParameters": {"event_id": EVENT_ID}}
response = lambda_client.invoke(
FunctionName = GET_NUM_ACTIVE_TOKENS_FN,
InvocationType = 'RequestResponse',
Payload = json.dumps(input_params)
)
result = response['Payload'].read()
out = json.loads(result)
body = json.loads(out["body"])
num_active_tokens = body["active_tokens"]
# get current queue_counter value
queue_counter_value = rc.get(QUEUE_COUNTER)
# get current serving_num value
serving_number_value = rc.get(SERVING_COUNTER)
# get total tokens generated
total_tokens = rc.get(TOKEN_COUNTER)
# get tokens marked completed
completed_sessions = rc.get(COMPLETED_SESSION_COUNTER)
# get tokens marked abandoned
abandoned_sessions = rc.get(ABANDONED_SESSION_COUNTER)
# write to event bus
try:
response = events_client.put_events(
Entries=[
{
'Source': 'custom.waitingroom',
'DetailType': 'waiting_room_metrics',
'Detail': json.dumps({"event_id": EVENT_ID,
"num_active_tokens": num_active_tokens,
"total_num_tokens": total_tokens,
"queue_counter": queue_counter_value,
"serving_number": serving_number_value,
"completed_sessions": completed_sessions,
"abandoned_sessions": abandoned_sessions}),
'EventBusName': EVENT_BUS_NAME
}
]
)
except Exception as exception:
print(exception)
raise exception
return response