Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 196be7a

Browse filesBrowse files
authored
fix(airflow_db_cleanup): sessions cleanup (GoogleCloudPlatform#11035)
This fixes an issue where the python operator gets killed if the ssession table is large neough
1 parent 980a984 commit 196be7a
Copy full SHA for 196be7a

File tree

Expand file treeCollapse file tree

1 file changed

+6
-17
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+6
-17
lines changed

‎composer/workflows/airflow_db_cleanup.py

Copy file name to clipboardExpand all lines: composer/workflows/airflow_db_cleanup.py
+6-17Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -468,24 +468,13 @@ def cleanup_sessions():
468468

469469
try:
470470
logging.info("Deleting sessions...")
471-
before = len(
472-
session.execute(
473-
text("SELECT * FROM session WHERE expiry < now()::timestamp(0);")
474-
)
475-
.mappings()
476-
.all()
477-
)
471+
count_statement = "SELECT COUNT(*) AS cnt FROM session WHERE expiry < now()::timestamp(0);"
472+
before = session.execute(text(count_statement)).one_or_none()["cnt"]
478473
session.execute(text("DELETE FROM session WHERE expiry < now()::timestamp(0);"))
479-
after = len(
480-
session.execute(
481-
text("SELECT * FROM session WHERE expiry < now()::timestamp(0);")
482-
)
483-
.mappings()
484-
.all()
485-
)
486-
logging.info("Deleted {} expired sessions.".format(before - after))
487-
except Exception as e:
488-
logging.error(e)
474+
after = session.execute(text(count_statement)).one_or_none()["cnt"]
475+
logging.info("Deleted %s expired sessions.", (before - after))
476+
except Exception as err:
477+
logging.exception(err)
489478

490479
session.commit()
491480
session.close()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.