Skip to content

Commit

Permalink
Add thread pool executor to allow concurrent device status retrievals
Browse files Browse the repository at this point in the history
  • Loading branch information
UsualSpec committed Jul 18, 2024
1 parent 5b5a6fc commit b63f575
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions server/management/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from datetime import datetime
import hashlib
from werkzeug.middleware.proxy_fix import ProxyFix
import concurrent.futures

allowedPpDevList = ["MCP1", "MCP2", "CPU"]

Expand Down Expand Up @@ -197,11 +198,11 @@ def getAllDeviceStatus():
pgcurs = pgConnection.cursor()
pgcurs.execute("SELECT client_uid FROM clients")
pgConnection.commit()
res = {}
for client in pgcurs:
# TODO: Speed this up e.g. by implementing a gRPC call directly to get all status messages from each device. This can wait a long time on timeouts
res[client[0]] = getDeviceStatus(client[0])
clients = pgcurs.fetchall()

# TODO: Speed this up e.g. by implementing a gRPC call directly to get all status messages from each device. This can wait a long time on timeouts
with concurrent.futures.ThreadPoolExecutor(max_workers=5) as tpe:
res = list(tpe.map(lambda client: {"name": client[0], "response": getDeviceStatus(client[0])}, clients))
return res

@app.route("/getLastMeasurementTimestampOfDevicePost", methods=["POST"])
Expand Down

0 comments on commit b63f575

Please sign in to comment.