fix: Webmention worker runs inside the app context (v2.6.8)
The worker thread called the SSRF checks, which read current_app.config, without an app context, so every incoming and outgoing webmention failed with 'Working outside of application context'. A teardown_appcontext hook also stopped the worker whenever a request ended. Pass the app to WebmentionWorker and run each poll in app.app_context(), like SyndicationWorker, and drop the teardown hook. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f924413934
commit
d43361d505
5 files changed
+127
-13
No files matched your search
@@ -25,7 +25,6 @@ from lxml import html as lxml_html
|
||||
|
||||
from starpunk.webmention_processor import process_webmention, ValidationError
|
||||
from starpunk.webmention_ssrf import validate_url_for_fetch, SSRFBlockedError
|
||||
from flask import has_app_context
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -47,6 +46,7 @@ class WebmentionWorker(threading.Thread):
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
app,
|
||||
db_path: Path,
|
||||
site_url: str,
|
||||
poll_interval: int = 10,
|
||||
@@ -58,6 +58,7 @@ class WebmentionWorker(threading.Thread):
|
||||
Initialize webmention worker thread
|
||||
|
||||
Args:
|
||||
app: Flask app (the SSRF checks read its config)
|
||||
db_path: Path to SQLite database
|
||||
site_url: Site URL for User-Agent header
|
||||
poll_interval: Seconds between queue checks (default: 10)
|
||||
@@ -66,6 +67,7 @@ class WebmentionWorker(threading.Thread):
|
||||
auto_approve: Auto-approve valid webmentions (default: True)
|
||||
"""
|
||||
super().__init__(daemon=True, name="webmention-worker")
|
||||
self.app = app
|
||||
self.db_path = db_path
|
||||
self.site_url = site_url
|
||||
self.poll_interval = poll_interval
|
||||
@@ -100,11 +102,12 @@ class WebmentionWorker(threading.Thread):
|
||||
try:
|
||||
processed = 0
|
||||
|
||||
# Process incoming webmentions
|
||||
processed += self._process_pending_validations()
|
||||
with self.app.app_context():
|
||||
# Process incoming webmentions
|
||||
processed += self._process_pending_validations()
|
||||
|
||||
# Phase 3: Process outgoing webmentions
|
||||
processed += self._process_pending_sends()
|
||||
# Phase 3: Process outgoing webmentions
|
||||
processed += self._process_pending_sends()
|
||||
|
||||
# Update last processed time
|
||||
if processed > 0:
|
||||
|
||||
Reference in new issue
Block a user