File tree Expand file tree Collapse file tree 2 files changed +14
-3
lines changed
Expand file tree Collapse file tree 2 files changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -74,7 +74,16 @@ def db_connect():
7474 connect_timeout = connect_timeout )
7575 except :
7676 db_pool = None
77- log .error ("DB connection failed" )
77+ log .exception ("DB connection failed" )
78+
79+
80+ def db_disconnect ():
81+ global db_pool
82+ if not db_pool :
83+ return
84+ db_pool .closeall ()
85+ db_pool = None
86+ log .info ("DB connection is closed" )
7887
7988
8089###########################
Original file line number Diff line number Diff line change 1414import psycopg2
1515
1616from grafoleancollector import Collector
17- from dbutils import get_db_cursor , DB_PREFIX , migrate_if_needed
17+ from dbutils import get_db_cursor , DB_PREFIX , migrate_if_needed , db_disconnect
1818
1919
2020logging .basicConfig (format = '%(asctime)s | %(levelname)s | %(message)s' ,
@@ -410,7 +410,6 @@ def jobs(self):
410410 Each entity (device) is a single job, no matter how many sensors it has. The reason is
411411 that when the intervals align, we can then issue a single SNMP Bulk GET/WALK.
412412 """
413- migrate_if_needed ()
414413 for entity_info in self .fetch_job_configs ('snmp' ):
415414 intervals = list (set ([sensor_info ["interval" ] for sensor_info in entity_info ["sensors" ]]))
416415 job_info = { ** entity_info , "backend_url" : self .backend_url , "bot_token" : self .bot_token }
@@ -444,6 +443,9 @@ def wait_for_grafolean(backend_url):
444443if __name__ == "__main__" :
445444 dotenv .load_dotenv ()
446445
446+ migrate_if_needed ()
447+ db_disconnect () # each worker should open their own connection pool
448+
447449 backend_url = os .environ .get ('BACKEND_URL' )
448450 jobs_refresh_interval = int (os .environ .get ('JOBS_REFRESH_INTERVAL' , 120 ))
449451
You can’t perform that action at this time.
0 commit comments