Skip to content

Commit 46e17c1

Browse files
author
Barbara Miller
committed
self._video_data in worker
1 parent 634b6a8 commit 46e17c1

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

brozzler/worker.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import datetime
2222
import io
2323
import json
24+
import os
2425
import socket
2526
import threading
2627
import time
@@ -39,6 +40,7 @@
3940
import brozzler
4041
import brozzler.browser
4142
from brozzler.model import VideoCaptureOptions
43+
from brozzler.ydl import VideoDataClient
4244

4345
from . import metrics
4446

@@ -56,6 +58,7 @@ class BrozzlerWorker:
5658
SITE_SESSION_MINUTES = 15
5759
HEADER_REQUEST_TIMEOUT = 30
5860
FETCH_URL_TIMEOUT = 60
61+
VIDEO_DATA_SOURCE = os.getenv("VIDEO_DATA_SOURCE")
5962

6063
def __init__(
6164
self,
@@ -88,6 +91,8 @@ def __init__(
8891
self._service_registry = service_registry
8992
self._ytdlp_proxy_endpoints = ytdlp_proxy_endpoints
9093
self._max_browsers = max_browsers
94+
if VIDEO_DATA_SOURCE and VIDEO_DATA_SOURCE.startswith("postgresql"):
95+
self._video_data = VideoDataClient()
9196

9297
self._warcprox_auto = warcprox_auto
9398
self._proxy = proxy

brozzler/ydl.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,16 @@
5151

5252

5353
class VideoDataClient:
54+
import psycopg
55+
from psycopg_pool import ConnectionPool, PoolTimeout
56+
5457
def __init__(self):
55-
if VIDEO_DATA_SOURCE and VIDEO_DATA_SOURCE.startswith("postgresql"):
56-
pool = ConnectionPool(VIDEO_DATA_SOURCE, min_size=1, max_size=9)
57-
pool.wait()
58-
logger.info("pg pool ready")
59-
# atexit.register(pool.close)
58+
pool = ConnectionPool(VIDEO_DATA_SOURCE, min_size=1, max_size=9)
59+
pool.wait()
60+
logger.info("pg pool ready")
61+
# atexit.register(pool.close)
6062

61-
self.pool = pool
63+
self.pool = pool
6264

6365
def _execute_pg_query(
6466
self, query: str, row_factory=None, fetchone=False, fetchall=False
@@ -512,10 +514,11 @@ def do_youtube_dl(worker, site, page, ytdlp_proxy_endpoints):
512514
or ie_result.get("extractor") == "youtube:tab"
513515
):
514516
if VIDEO_DATA_SOURCE and VIDEO_DATA_SOURCE.startswith("postgresql"):
515-
video_data = VideoDataClient()
516517
captured_youtube_watch_pages = set()
517518
captured_youtube_watch_pages.add(
518-
video_data.get_pg_video_captures_by_source(site, source="youtube")
519+
worker._video_data.get_pg_video_captures_by_source(
520+
site, source="youtube"
521+
)
519522
)
520523
uncaptured_youtube_watch_pages = []
521524
for e in ie_result.get("entries_no_dl", []):

0 commit comments

Comments
 (0)