diff options
| author | salmonik <raisersoft@proton.me> | 2026-04-29 14:22:03 +0200 |
|---|---|---|
| committer | salmonik <raisersoft@proton.me> | 2026-04-29 14:22:03 +0200 |
| commit | dba3388567818cb5c60be9d406d3e1cccc84b3ea (patch) | |
| tree | 53a0903f7a4c381c7ad12e3e632ef8dd8ebba39f /cogs/cron.py | |
| parent | multitude of changes. (diff) | |
| download | senator-sperma-dba3388567818cb5c60be9d406d3e1cccc84b3ea.tar.gz senator-sperma-dba3388567818cb5c60be9d406d3e1cccc84b3ea.zip | |
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
Diffstat (limited to '')
| -rw-r--r-- | cogs/cron.py | 11 |
1 files changed, 2 insertions, 9 deletions
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): | |||
| 30 | 30 | ||
| 31 | def load_tasks(self): | 31 | def load_tasks(self): |
| 32 | try: | 32 | try: |
| 33 | conn = get_connection() | 33 | with get_connection() as conn: |
| 34 | try: | ||
| 35 | c = conn.cursor() | 34 | c = conn.cursor() |
| 36 | c.execute("SELECT id, cron_expression, type, channel_id, active, audio_filename, message FROM cron_jobs") | 35 | c.execute("SELECT id, cron_expression, type, channel_id, active, audio_filename, message FROM cron_jobs") |
| 37 | rows = c.fetchall() | 36 | rows = c.fetchall() |
| 38 | finally: | ||
| 39 | conn.close() | ||
| 40 | 37 | ||
| 41 | self.scheduled_tasks = [ | 38 | self.scheduled_tasks = [ |
| 42 | { | 39 | { |
| @@ -57,8 +54,7 @@ class Cron(commands.Cog): | |||
| 57 | 54 | ||
| 58 | def save_tasks(self): | 55 | def save_tasks(self): |
| 59 | try: | 56 | try: |
| 60 | conn = get_connection() | 57 | with get_connection() as conn: |
| 61 | try: | ||
| 62 | c = conn.cursor() | 58 | c = conn.cursor() |
| 63 | c.execute("PRAGMA foreign_keys = ON") | 59 | c.execute("PRAGMA foreign_keys = ON") |
| 64 | 60 | ||
| @@ -78,10 +74,7 @@ class Cron(commands.Cog): | |||
| 78 | task.get("message"), | 74 | task.get("message"), |
| 79 | ), | 75 | ), |
| 80 | ) | 76 | ) |
| 81 | |||
| 82 | conn.commit() | 77 | conn.commit() |
| 83 | finally: | ||
| 84 | conn.close() | ||
| 85 | except Exception as e: | 78 | except Exception as e: |
| 86 | logger.error(f"Error saving cron jobs: {e}") | 79 | logger.error(f"Error saving cron jobs: {e}") |
| 87 | 80 | ||
