From dba3388567818cb5c60be9d406d3e1cccc84b3ea Mon Sep 17 00:00:00 2001 From: salmonik Date: Wed, 29 Apr 2026 14:22:03 +0200 Subject: Refactor database connections and add integration tests - Use context managers for sqlite3 connections in cron, vclogs, and database utils - Add URL helper utility for yt-dlp with clean_url_for_ytdlp function - Add slow integration test markers and new integration test files - Fix test imports to use conftest directly instead of tests.conftest - Improve downloader error handling and use COPYPARTY_URL_UPLOAD env var - Update pytest.ini with slow test markers and warning filters - Document slow test usage in AGENTS.md --- cogs/cron.py | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) (limited to 'cogs/cron.py') diff --git a/cogs/cron.py b/cogs/cron.py index b4f494a..aad43d2 100644 --- a/cogs/cron.py +++ b/cogs/cron.py @@ -30,13 +30,10 @@ class Cron(commands.Cog): def load_tasks(self): try: - conn = get_connection() - try: + with get_connection() as conn: c = conn.cursor() c.execute("SELECT id, cron_expression, type, channel_id, active, audio_filename, message FROM cron_jobs") rows = c.fetchall() - finally: - conn.close() self.scheduled_tasks = [ { @@ -57,8 +54,7 @@ class Cron(commands.Cog): def save_tasks(self): try: - conn = get_connection() - try: + with get_connection() as conn: c = conn.cursor() c.execute("PRAGMA foreign_keys = ON") @@ -78,10 +74,7 @@ class Cron(commands.Cog): task.get("message"), ), ) - conn.commit() - finally: - conn.close() except Exception as e: logger.error(f"Error saving cron jobs: {e}") -- cgit v1.2.3