Skip to content
Snippets Groups Projects
Commit 12ff49f1 authored by Sybren A. Stüvel's avatar Sybren A. Stüvel
Browse files

Throttle 'output produced' messages to Manager

parent 93db5a81
No related branches found
No related tags found
No related merge requests found
...@@ -5,6 +5,7 @@ import functools ...@@ -5,6 +5,7 @@ import functools
import itertools import itertools
import pathlib import pathlib
import tempfile import tempfile
import time
import traceback import traceback
import typing import typing
...@@ -149,6 +150,8 @@ class FlamencoWorker: ...@@ -149,6 +150,8 @@ class FlamencoWorker:
_log = attrs_extra.log('%s.FlamencoWorker' % __name__) _log = attrs_extra.log('%s.FlamencoWorker' % __name__)
_last_output_produced = 0.0 # seconds since epoch
@property @property
def active_task_id(self) -> typing.Optional[str]: def active_task_id(self) -> typing.Optional[str]:
"""Returns the task ID, but only if it is currently executing; returns None otherwise.""" """Returns the task ID, but only if it is currently executing; returns None otherwise."""
...@@ -663,8 +666,17 @@ class FlamencoWorker: ...@@ -663,8 +666,17 @@ class FlamencoWorker:
This performs a HTTP POST in a background task, returning as soon as This performs a HTTP POST in a background task, returning as soon as
the task is scheduled. the task is scheduled.
Only sends an update every X seconds, to avoid sending too many
requests when we output frames rapidly.
""" """
now = time.time()
if now - self._last_output_produced < 30:
self._log.debug('Throttling POST to Manager /output-produced endpoint')
return
self._last_output_produced = now
async def do_post(): async def do_post():
try: try:
self._log.info('Sending %i path(s) to Manager', len(paths)) self._log.info('Sending %i path(s) to Manager', len(paths))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment