forked from 0xWheatyz/SPARC
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 417b7ab31e | |||
| a07a0c7fbe | |||
| 43fd2c9575 | |||
| d4d43cf9b8 |
+12
-7
@@ -2,14 +2,17 @@
|
|||||||
|
|
||||||
Uses APScheduler to periodically re-analyze tracked companies and
|
Uses APScheduler to periodically re-analyze tracked companies and
|
||||||
detect significant changes in patent counts.
|
detect significant changes in patent counts.
|
||||||
|
|
||||||
|
The scheduler reuses the application-level pooled DatabaseClient
|
||||||
|
(from ``SPARC.auth``) instead of creating its own connection, which
|
||||||
|
avoids exhausting the database connection pool under load.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from SPARC import config
|
|
||||||
from SPARC.analyzer import CompanyAnalyzer
|
from SPARC.analyzer import CompanyAnalyzer
|
||||||
from SPARC.database import DatabaseClient
|
from SPARC.auth import get_db_client
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -21,10 +24,13 @@ CHANGE_THRESHOLD_PERCENT = int(os.getenv("CHANGE_THRESHOLD_PERCENT", "20"))
|
|||||||
|
|
||||||
|
|
||||||
def run_scheduled_analysis() -> None:
|
def run_scheduled_analysis() -> None:
|
||||||
"""Re-analyze all tracked companies and check for significant changes."""
|
"""Re-analyze all tracked companies and check for significant changes.
|
||||||
db = DatabaseClient(config.database_url)
|
|
||||||
db.connect()
|
Uses the shared pooled DatabaseClient from ``SPARC.auth.get_db_client()``
|
||||||
db.initialize_schema()
|
rather than creating a disposable connection, so the scheduler participates
|
||||||
|
in the same connection pool as the rest of the application.
|
||||||
|
"""
|
||||||
|
db = get_db_client()
|
||||||
|
|
||||||
tracked = db.list_tracked_companies()
|
tracked = db.list_tracked_companies()
|
||||||
if not tracked:
|
if not tracked:
|
||||||
@@ -74,7 +80,6 @@ def run_scheduled_analysis() -> None:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error("Error analyzing tracked company %s: %s", name, e)
|
logger.error("Error analyzing tracked company %s: %s", name, e)
|
||||||
|
|
||||||
db.close()
|
|
||||||
logger.info("Scheduled analysis complete")
|
logger.info("Scheduled analysis complete")
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -159,7 +159,7 @@ export function Analysis() {
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="prose prose-invert max-w-none">
|
<div className="prose dark:prose-invert max-w-none">
|
||||||
<div className="text-text-primary whitespace-pre-wrap leading-relaxed">
|
<div className="text-text-primary whitespace-pre-wrap leading-relaxed">
|
||||||
{result.analysis}
|
{result.analysis}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user