ephraimbuddy commented on a change in pull request #19931:
URL: https://github.com/apache/airflow/pull/19931#discussion_r768705442
##########
File path: airflow/models/pool.py
##########
@@ -78,6 +86,54 @@ def get_default_pool(session: Session = None):
"""
return Pool.get_pool(Pool.DEFAULT_POOL_NAME, session=session)
+ @staticmethod
+ @provide_session
+ def create_or_update_pool(name, slots, description, session=None):
+ """Create a pool with given parameters or update it if it already
exists."""
+ if not (name and name.strip()):
+ raise AirflowBadRequest("Pool name shouldn't be empty")
+ try:
+ slots = int(slots)
+ except ValueError:
+ raise AirflowBadRequest(f"Bad value for `slots`: {slots}")
+
+ # Get the length of the pool column
+ pool_name_length = Pool.pool.property.columns[0].type.length
+ if len(name) > pool_name_length:
+ raise AirflowBadRequest(f"Pool name can't be more than
{pool_name_length} characters")
+
+ session.expire_on_commit = False
+ pool = session.query(Pool).filter_by(pool=name).first()
+ if pool is None:
+ pool = Pool(pool=name, slots=slots, description=description)
+ session.add(pool)
+ else:
+ pool.slots = slots
+ pool.description = description
+
+ session.commit()
+
+ return pool
+
+ @staticmethod
+ @provide_session
+ def delete_pool(name, session=None):
+ """Delete pool by a given name."""
+ if not (name and name.strip()):
+ raise AirflowBadRequest("Pool name shouldn't be empty")
Review comment:
I will address it
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]