File tree Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Original file line number Diff line number Diff line change 14
14
Sequence ,
15
15
)
16
16
17
- from psycopg import sql , connect
17
+ from psycopg import sql , connect , Connection
18
18
19
19
# supported only from 3.11 onwards:
20
20
# from datetime import UTC
@@ -69,19 +69,28 @@ def __init__(
69
69
# called when ttl <= 0 for a task
70
70
self .ttl_zero_callback = ttl_zero_callback
71
71
72
- self .connect ()
72
+ self .conn = self . connect ()
73
73
if create_table :
74
74
self ._create_queue_table ()
75
75
76
76
if reset :
77
77
self ._reset ()
78
78
79
+ def get_connection (self ):
80
+ connection = connect (self ._dsn )
81
+ with connection .cursor () as cur :
82
+ cur .execute ("SELECT 1+1" )
83
+ cur .fetchone ()
84
+
85
+ return connection
86
+
79
87
def connect (self ) -> None :
80
88
"""
81
89
Establish a connection to Postgres.
82
90
If a connection already exists, it's overwritten.
83
91
"""
84
- self .conn = connect (self ._dsn )
92
+ if self .conn is None or self .conn .closed :
93
+ self .conn = self .get_connection ()
85
94
86
95
def _create_queue_table (self ) -> None :
87
96
"""
You can’t perform that action at this time.
0 commit comments