close-connection-after-each-batch-using-with (#6641)

This commit is contained in:
Abhishek Pandey 2022-08-09 11:15:56 +05:30 committed by GitHub
parent 555962dfd3
commit 77ad1b1c87
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -49,7 +49,6 @@ class UsageSource(Source[TableQuery], ABC):
self.start, self.end = get_start_and_end(self.source_config.queryLogDuration)
self.analysis_date = self.end
self.report = SQLSourceStatus()
self.engine = get_connection(self.connection)
def prepare(self):
return super().prepare()
@ -117,7 +116,8 @@ class UsageSource(Source[TableQuery], ABC):
f"Scanning query logs for {(self.start+timedelta(days=i)).date()} - {(self.start+timedelta(days=i+1)).date()}"
)
try:
rows = self.engine.execute(
with get_connection(self.connection).connect() as conn:
rows = conn.execute(
self.get_sql_statement(
start_time=self.start + timedelta(days=i),
end_time=self.start + timedelta(days=i + 1),