Added reporter
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Pünkösd Marcell 2021-12-03 00:31:30 +01:00
parent 99aa33b1df
commit cf6ea3959c
3 changed files with 36 additions and 0 deletions

View File

@ -14,6 +14,8 @@ opentracing~=2.4.0
cython
apscheduler
six
deprecation

View File

@ -11,3 +11,7 @@ class Config:
INPUT_SERVICE_URL = os.environ.get("INPUT_SERVICE_URL", "http://input-service/input")
DROPALL = os.environ.get("DROPALL", "no").lower() in ['yes', 'true', '1']
REPORT_ALIAS = os.environ.get("REPORTER_ALIAS", os.environ['HOSTNAME'])
REPORT_URL = os.environ.get("REPORT_URL", "")
REPORT_INTERVAL = int(os.environ.get("REPORT_INTERVAL", 15))

View File

@ -15,6 +15,8 @@ from pyAudioAnalysis import audioBasicIO
from pyAudioAnalysis import MidTermFeatures
import numpy
from apscheduler.schedulers.background import BackgroundScheduler
if Config.SENTRY_DSN:
sentry_sdk.init(
dsn=Config.SENTRY_DSN,
@ -119,12 +121,37 @@ def lapatolas(q: Queue):
q.put(message)
def reporter(q: Queue):
report = {
"site": Config.REPORT_ALIAS,
"measurements": {
"queue": q.qsize()
}
}
print("Reporting queue length of", report)
r = requests.post(Config.REPORT_URL, json=report)
r.raise_for_status()
if r.status_code != 201:
print(Config.REPORT_URL, "Wrong response:", r.status_code)
def main():
memer = ModelMemer()
requeue = Queue()
Thread(target=lapatolas, args=(requeue,), daemon=True).start()
scheduler = None
if Config.REPORT_URL:
scheduler = BackgroundScheduler()
scheduler.add_job(lambda: reporter(requeue), trigger='interval', seconds=Config.REPORT_INTERVAL)
scheduler.start()
Thread(target=reporter, args=(requeue,), daemon=True).start()
while True:
message = requeue.get(block=True)
task = pickle.loads(message)
@ -149,6 +176,9 @@ def main():
finally:
os.remove(audio_file_path)
# if scheduler:
# scheduler.stop()
if __name__ == '__main__':
main()