aboutsummaryrefslogtreecommitdiffstats
path: root/cogs/cron.py
diff options
context:
space:
mode:
Diffstat (limited to 'cogs/cron.py')
-rw-r--r--cogs/cron.py11
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