fix(proxy): reset added timestamp on hot spare promotion

This commit is contained in:
Iain Learmonth 2023-05-31 12:58:36 +01:00
parent 8115966aca
commit 5d00dc8fe1

View file

@ -168,13 +168,14 @@ def promote_hot_spare_proxy(pool_id: int, origin: Origin) -> bool:
This function searches for a 'hot spare' proxy (a proxy in reserve pool with pool_id == -1) This function searches for a 'hot spare' proxy (a proxy in reserve pool with pool_id == -1)
for the given origin. If a proxy is found, it is promoted to the specified pool by changing its pool ID. for the given origin. If a proxy is found, it is promoted to the specified pool by changing its pool ID.
The added timestamp is also reset to the time at which the hot spare was promoted.
:param pool_id: The pool to which the 'hot spare' proxy is to be promoted. :param pool_id: The pool to which the 'hot spare' proxy is to be promoted.
:param origin: The origin of the 'hot spare' proxy to be promoted. :param origin: The origin of the 'hot spare' proxy to be promoted.
:return: True if a 'hot spare' proxy was found and promoted, False otherwise. :return: True if a 'hot spare' proxy was found and promoted, False otherwise.
.. note:: In the database, the pool ID -1 signifies a reserve pool of 'hot spare' proxies. This pool does not .. note:: In the database, the pool ID -1 signifies a reserve pool of 'hot spare' proxies. This pool is created by
appear in the pool table and is only used as a sentinel value. default in the schema migrations.
""" """
proxy = Proxy.query.filter( proxy = Proxy.query.filter(
Proxy.pool_id == -1, Proxy.pool_id == -1,
@ -183,6 +184,7 @@ def promote_hot_spare_proxy(pool_id: int, origin: Origin) -> bool:
if not proxy: if not proxy:
return False return False
proxy.pool_id = pool_id proxy.pool_id = pool_id
proxy.added = datetime.datetime.utcnow()
return True return True