From 35a1e842136cdcaa60ed40416dc9631af72f5a98 Mon Sep 17 00:00:00 2001 From: Karl Mathias Moberg Date: Mon, 15 Jan 2024 21:16:27 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Fix=20signal=20alarm=20issue?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 46 ++++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/main.py b/main.py index 66a03ed..22a8f89 100644 --- a/main.py +++ b/main.py @@ -1,7 +1,6 @@ import cProfile import json import os -import signal import time import urllib.parse @@ -69,9 +68,6 @@ def timeout_handler(signum, frame): raise TimeoutException("Timeout handler triggered!") -# signal.signal(signal.SIGALRM, timeout_handler) - - zny_web_instance = "https://nyartcc.org" @@ -186,8 +182,6 @@ def updateUsers(ts3conn, conn): :return: """ - conn = conn - def sendMessageReg(client_unique_identifier, clid): """ Send a message to a user to register on the ZNY website. @@ -357,19 +351,27 @@ def lambda_handler(event, context): # Get the IP address of the ZNY-Website-Production EC2 instance # zny_web_instance_ip = ZNY_WEB_SERVER_IP - signal.alarm(15) - - with ts3.query.TS3Connection(tsHostname, "10011") as ts3conn: - ts3conn.login(client_login_name=tsUsername, client_login_password=tsPass) - ts3conn.use(sid=1) - conn = engine.connect() - updatePos(ts3conn, conn) - updateUsers(ts3conn, conn) - - return { - "statusCode": 200, - "headers": {}, - "body": json.dumps({ - "message": f"Ran successfully! {updateCount} updates were made. {failCount} failed.", - }), - } + + try: + with ts3.query.TS3Connection(tsHostname, "10011") as ts3conn: + ts3conn.login(client_login_name=tsUsername, client_login_password=tsPass) + ts3conn.use(sid=1) + conn = engine.connect() + updatePos(ts3conn, conn) + updateUsers(ts3conn, conn) + + return { + "statusCode": 200, + "headers": {}, + "body": json.dumps({ + "message": f"Ran successfully! {updateCount} updates were made. {failCount} failed.", + }), + } + except Error as e: + return { + "statusCode": 500, + "headers": {}, + "body": json.dumps({ + "message": f"Timed out after 15 seconds." + }), + }