Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor external events handler #6923

Draft
wants to merge 4 commits into
base: dev
Choose a base branch
from

Conversation

skrashevich
Copy link
Contributor

separate logic and API handlers. It's now possible to create "external" events without requesting the http server.

For example, possible changes on audio-events:

---
 frigate/events/audio.py | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/frigate/events/audio.py b/frigate/events/audio.py
index 0decb001b..f1354e633 100644
--- a/frigate/events/audio.py
+++ b/frigate/events/audio.py
@@ -21,6 +21,7 @@
     AUDIO_SAMPLE_RATE,
     CACHE_DIR,
 )
+from frigate.events.external import create_event, end_event
 from frigate.ffmpeg_presets import parse_preset_input
 from frigate.log import LogPipe
 from frigate.object_detection import load_labels
@@ -184,10 +185,7 @@ def handle_detection(self, label: str, score: float) -> None:
                 "last_detection"
             ] = datetime.datetime.now().timestamp()
         else:
-            resp = requests.post(
-                f"http:https://127.0.0.1:5000/api/events/{self.config.name}/{label}/create",
-                json={"duration": None},
-            )
+            resp = create_event(self.config.name, label, {"duration": None})
 
             if resp.status_code == 200:
                 event_id = resp.json()[0]["event_id"]
@@ -205,11 +203,11 @@ def expire_detections(self) -> None:
                 now - detection.get("last_detection", now)
                 > self.config.audio.max_not_heard
             ):
-                resp = requests.put(
-                    f"http:https://127.0.0.1/api/events/{detection['id']}/end",
-                    json={
-                        "end_time": detection["last_detection"]
-                        + self.config.record.events.post_capture
+                resp = end_event(
+                    detection["id"],
+                    {
+                        "end_time": detection["last_detection"] * 1
+                        + self.config.record.events.post_capture * 1
                     },
                 )
                 if resp.status_code == 200:

@netlify
Copy link

netlify bot commented Jun 26, 2023

Deploy Preview for frigate-docs canceled.

Name Link
🔨 Latest commit 99f23c4
🔍 Latest deploy log https://app.netlify.com/sites/frigate-docs/deploys/64999565ed9afb00087bc051

@NickM-27
Copy link
Sponsor Collaborator

I don't think we want Flask being used outside of the http module, this breaks separation of concerns

@NickM-27
Copy link
Sponsor Collaborator

This also wouldn't work for the audio events feature because audio events are handled in a separate process so current_app wouldn't be set.

I don't see any problem with the way things are currently done.

@skrashevich skrashevich force-pushed the 230626-refactor-external-events-handler branch from fb83303 to 99f23c4 Compare June 26, 2023 13:40
@skrashevich skrashevich marked this pull request as draft June 26, 2023 13:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants