From 072cba8ce7e6c4e572f809b46bb3c961d8f680cc Mon Sep 17 00:00:00 2001 From: John Schoewe Date: Thu, 20 Aug 2026 15:11:05 -0400 Subject: [PATCH 1/2] Added exe_id param to execution purge script to allow for deleting single executions instead of everything older than a certain date --- st2common/st2common/cmd/purge_executions.py | 13 ++++++++--- .../garbage_collection/executions.py | 23 +++++++++++-------- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/st2common/st2common/cmd/purge_executions.py b/st2common/st2common/cmd/purge_executions.py index 27225d661c..ae3cc45f13 100644 --- a/st2common/st2common/cmd/purge_executions.py +++ b/st2common/st2common/cmd/purge_executions.py @@ -62,6 +62,11 @@ def _register_cli_opts(): + 'By default, only executions in completed states such as "succeeeded" ' + ', "failed", "canceled" and "timed_out" are deleted.', ), + cfg.StrOpt( + "execution-id", + default="", + help="Execution ID to purge.", + ), ] do_register_cli_opts(cli_opts) @@ -74,11 +79,12 @@ def main(): timestamp = cfg.CONF.timestamp action_ref = cfg.CONF.action_ref purge_incomplete = cfg.CONF.purge_incomplete + execution_id = cfg.CONF.execution_id - if not timestamp: - LOG.error("Please supply a timestamp for purging models. Aborting.") + if not execution_id and not timestamp: + LOG.error("Please supply a timestamp or execution ID for purging models. Aborting.") return 1 - else: + if timestamp: timestamp = datetime.strptime(timestamp, "%Y-%m-%dT%H:%M:%S.%fZ") timestamp = timestamp.replace(tzinfo=pytz.UTC) @@ -88,6 +94,7 @@ def main(): timestamp=timestamp, action_ref=action_ref, purge_incomplete=purge_incomplete, + exe_id=execution_id, ) except Exception as e: LOG.exception(six.text_type(e)) diff --git a/st2common/st2common/garbage_collection/executions.py b/st2common/st2common/garbage_collection/executions.py index bc0e85f1f0..83342185b5 100644 --- a/st2common/st2common/garbage_collection/executions.py +++ b/st2common/st2common/garbage_collection/executions.py @@ -42,7 +42,7 @@ ] -def purge_executions(logger, timestamp, action_ref=None, purge_incomplete=False): +def purge_executions(logger, timestamp, action_ref=None, purge_incomplete=False, exe_id=None): """ Purge action executions and corresponding live action, execution output objects. @@ -55,17 +55,22 @@ def purge_executions(logger, timestamp, action_ref=None, purge_incomplete=False) :param purge_incomplete: True to also delete executions which are not in a done state. :type purge_incomplete: ``bool`` """ - if not timestamp: - raise ValueError("Specify a valid timestamp to purge.") - - logger.info( - "Purging executions older than timestamp: %s" - % timestamp.strftime("%Y-%m-%dT%H:%M:%S.%fZ") - ) + if not timestamp and not exe_id: + raise ValueError("Specify a valid timestamp or execution ID to purge.") + + if exe_id: + logger.info("Purging execution with ID: %s" % exe_id) + elif timestamp: + logger.info( + "Purging executions older than timestamp: %s" + % timestamp.strftime("%Y-%m-%dT%H:%M:%S.%fZ") + ) filters = {} - if purge_incomplete: + if exe_id: + filters["id"] = exe_id + elif purge_incomplete: filters["start_timestamp__lt"] = timestamp else: filters["end_timestamp__lt"] = timestamp From 447da024c7e40195113871f9f468e35de8a0a0b1 Mon Sep 17 00:00:00 2001 From: John Schoewe Date: Thu, 20 Aug 2026 15:14:47 -0400 Subject: [PATCH 2/2] Added exe_id param to execution purge script to allow for deleting single executions instead of everything older than a certain date --- st2common/st2common/cmd/purge_executions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/st2common/st2common/cmd/purge_executions.py b/st2common/st2common/cmd/purge_executions.py index ae3cc45f13..4a67e9a2f3 100644 --- a/st2common/st2common/cmd/purge_executions.py +++ b/st2common/st2common/cmd/purge_executions.py @@ -64,7 +64,7 @@ def _register_cli_opts(): ), cfg.StrOpt( "execution-id", - default="", + default=None, help="Execution ID to purge.", ), ]