Skip to content

Commit 8703dd7

Browse files
committed
update config when necessary
1 parent 4b97713 commit 8703dd7

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

src/service/agent/helpers.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -264,20 +264,21 @@ def update_resource(backend: str, message: backend_messages.UpdateNodeBody,
264264
timestamp,
265265
)
266266

267-
postgres.execute_commit_command(commit_cmd, columns)
268-
pool_config = connectors.fetch_verbose_pool_config(postgres, backend)
269-
resource_entry = workflow.ResourcesEntry(hostname=message.hostname,
270-
label_fields=message.label_fields,
271-
backend=backend, taints=message.taints,
272-
# Dummy placeholder values below
273-
exposed_fields={},
274-
usage_fields={},
275-
non_workflow_usage_fields={},
276-
allocatable_fields={},
277-
pool_platform_labels={},
278-
resource_type=connectors.BackendResourceType.SHARED,
279-
conditions=message.conditions)
280-
config_helpers.update_node_pool_platform(resource_entry, backend, pool_config)
267+
rowcount = postgres.execute_commit_command(commit_cmd, columns)
268+
if rowcount > 0:
269+
pool_config = connectors.fetch_verbose_pool_config(postgres, backend)
270+
resource_entry = workflow.ResourcesEntry(hostname=message.hostname,
271+
label_fields=message.label_fields,
272+
backend=backend, taints=message.taints,
273+
# Dummy placeholder values below
274+
exposed_fields={},
275+
usage_fields={},
276+
non_workflow_usage_fields={},
277+
allocatable_fields={},
278+
pool_platform_labels={},
279+
resource_type=connectors.BackendResourceType.SHARED,
280+
conditions=message.conditions)
281+
config_helpers.update_node_pool_platform(resource_entry, backend, pool_config)
281282

282283

283284
def update_resource_usage(backend: str, message: backend_messages.UpdateNodeUsageBody,

src/utils/connectors/postgres.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,14 +475,17 @@ def execute_fetch_command(self, command: str,
475475
cur.close()
476476

477477
@retry
478-
def execute_commit_command(self, command: str, args: Tuple):
478+
def execute_commit_command(self, command: str, args: Tuple) -> int:
479479
"""
480480
Connects and executes a command that updates the database.
481481
482482
Args:
483483
command (str): The command to execute.
484484
args (Tuple): Any args for the command.
485485
486+
Returns:
487+
int: The number of rows affected by the command.
488+
486489
Raises:
487490
OSMODatabaseError: Error while executing the database command.
488491
"""
@@ -491,8 +494,10 @@ def execute_commit_command(self, command: str, args: Tuple):
491494
try:
492495
cur = conn.cursor()
493496
cur.execute(command, args)
497+
rowcount = cur.rowcount
494498
cur.close()
495499
conn.commit()
500+
return rowcount
496501
except (psycopg2.DatabaseError, psycopg2.InterfaceError) as error:
497502
try:
498503
if cur is not None:

0 commit comments

Comments
 (0)