Skip to content

Commit d25d43f

Browse files
authored
Merge pull request #5605 from StackStorm/merge_purge_workflows
Changes to support new purge task executions and purge workflows
2 parents ec8f33e + a478683 commit d25d43f

15 files changed

Lines changed: 750 additions & 0 deletions

File tree

CHANGELOG.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ Added
155155
* Added garbage collection for rule_enforcement and trace models #5596/5602
156156
Contributed by Amanda McGuinness (@amanda11 intive)
157157

158+
* Added garbage collection for workflow execution and task execution objects #4924
159+
Contributed by @srimandaleeka01 and @amanda11
160+
158161

159162
Fixed
160163
~~~~~

conf/st2.conf.sample

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,14 @@ purge_inquiries = False
181181
rule_enforcements_ttl = None
182182
# How long to wait / sleep (in seconds) between collection of different object types.
183183
sleep_delay = 2
184+
# Workflow task execution output objects (generated by action output streaming) older than this value (days) will be automatically deleted. Defaults to None (disabled).
185+
task_executions_ttl = None
184186
# Trace objects older than this value (days) will be automatically deleted. Defaults to None (disabled).
185187
traces_ttl = None
186188
# Trigger instances older than this value (days) will be automatically deleted. Defaults to None (disabled).
187189
trigger_instances_ttl = None
190+
# Workflow execution output objects (generated by action output streaming) older than this value (days) will be automatically deleted. Defaults to None (disabled).
191+
workflow_executions_ttl = None
188192

189193
[keyvalue]
190194
# Allow encryption of values in key value stored qualified as "secret".
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env python
2+
# Licensed to the StackStorm, Inc ('StackStorm') under one or more
3+
# contributor license agreements. See the NOTICE file distributed with
4+
# this work for additional information regarding copyright ownership.
5+
# The ASF licenses this file to You under the Apache License, Version 2.0
6+
# (the "License"); you may not use this file except in compliance with
7+
# the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
import sys
18+
19+
from st2common.cmd.purge_task_executions import main
20+
21+
if __name__ == '__main__':
22+
sys.exit(main())

st2common/bin/st2-purge-workflows

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env python
2+
# Licensed to the StackStorm, Inc ('StackStorm') under one or more
3+
# contributor license agreements. See the NOTICE file distributed with
4+
# this work for additional information regarding copyright ownership.
5+
# The ASF licenses this file to You under the Apache License, Version 2.0
6+
# (the "License"); you may not use this file except in compliance with
7+
# the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
import sys
18+
19+
from st2common.cmd.purge_workflows import main
20+
21+
if __name__ == '__main__':
22+
sys.exit(main())

st2common/setup.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@
5252
"bin/st2-cleanup-db",
5353
"bin/st2-register-content",
5454
"bin/st2-purge-executions",
55+
"bin/st2-purge-workflows",
56+
"bin/st2-purge-task-executions",
5557
"bin/st2-purge-trigger-instances",
5658
"bin/st2-purge-traces",
5759
"bin/st2-purge-rule-enforcements",
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# Copyright 2022 The StackStorm Authors.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
16+
"""
17+
A utility script that purges st2 workflow task executions older than certain
18+
timestamp.
19+
20+
*** RISK RISK RISK. You will lose data. Run at your own risk. ***
21+
"""
22+
23+
from __future__ import absolute_import
24+
25+
from datetime import datetime
26+
27+
import six
28+
import pytz
29+
from oslo_config import cfg
30+
31+
from st2common import config
32+
from st2common import log as logging
33+
from st2common.config import do_register_cli_opts
34+
from st2common.script_setup import setup as common_setup
35+
from st2common.script_setup import teardown as common_teardown
36+
from st2common.constants.exit_codes import SUCCESS_EXIT_CODE
37+
from st2common.constants.exit_codes import FAILURE_EXIT_CODE
38+
from st2common.garbage_collection.workflows import purge_task_executions
39+
40+
__all__ = ["main"]
41+
42+
LOG = logging.getLogger(__name__)
43+
44+
45+
def _register_cli_opts():
46+
cli_opts = [
47+
cfg.StrOpt(
48+
"timestamp",
49+
default=None,
50+
help="Will delete workflow task execution objects older than "
51+
+ "this UTC timestamp. "
52+
+ "Example value: 2015-03-13T19:01:27.255542Z.",
53+
),
54+
cfg.BoolOpt(
55+
"purge-incomplete",
56+
default=False,
57+
help="Purge all models irrespective of their ``status``."
58+
+ "By default, only workflow task executions in completed states such as "
59+
+ '"succeeeded", "failed", "canceled" and "timed_out" are deleted.',
60+
),
61+
]
62+
do_register_cli_opts(cli_opts)
63+
64+
65+
def main():
66+
_register_cli_opts()
67+
common_setup(config=config, setup_db=True, register_mq_exchanges=False)
68+
69+
# Get config values
70+
timestamp = cfg.CONF.timestamp
71+
purge_incomplete = cfg.CONF.purge_incomplete
72+
73+
if not timestamp:
74+
LOG.error("Please supply a timestamp for purging models. Aborting.")
75+
return 1
76+
else:
77+
timestamp = datetime.strptime(timestamp, "%Y-%m-%dT%H:%M:%S.%fZ")
78+
timestamp = timestamp.replace(tzinfo=pytz.UTC)
79+
80+
try:
81+
purge_task_executions(
82+
logger=LOG, timestamp=timestamp, purge_incomplete=purge_incomplete
83+
)
84+
except Exception as e:
85+
LOG.exception(six.text_type(e))
86+
return FAILURE_EXIT_CODE
87+
finally:
88+
common_teardown()
89+
90+
return SUCCESS_EXIT_CODE
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# Copyright 2022 The StackStorm Authors.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
16+
"""
17+
A utility script that purges st2 workflow executions older than certain
18+
timestamp.
19+
20+
*** RISK RISK RISK. You will lose data. Run at your own risk. ***
21+
"""
22+
23+
from __future__ import absolute_import
24+
25+
from datetime import datetime
26+
27+
import six
28+
import pytz
29+
from oslo_config import cfg
30+
31+
from st2common import config
32+
from st2common import log as logging
33+
from st2common.config import do_register_cli_opts
34+
from st2common.script_setup import setup as common_setup
35+
from st2common.script_setup import teardown as common_teardown
36+
from st2common.constants.exit_codes import SUCCESS_EXIT_CODE
37+
from st2common.constants.exit_codes import FAILURE_EXIT_CODE
38+
from st2common.garbage_collection.workflows import purge_workflow_executions
39+
40+
__all__ = ["main"]
41+
42+
LOG = logging.getLogger(__name__)
43+
44+
45+
def _register_cli_opts():
46+
cli_opts = [
47+
cfg.StrOpt(
48+
"timestamp",
49+
default=None,
50+
help="Will delete workflow execution objects older than "
51+
+ "this UTC timestamp. "
52+
+ "Example value: 2015-03-13T19:01:27.255542Z.",
53+
),
54+
cfg.BoolOpt(
55+
"purge-incomplete",
56+
default=False,
57+
help="Purge all models irrespective of their ``status``."
58+
+ "By default, only workflow executions in completed states such as "
59+
+ '"succeeeded", "failed", "canceled" and "timed_out" are deleted.',
60+
),
61+
]
62+
do_register_cli_opts(cli_opts)
63+
64+
65+
def main():
66+
_register_cli_opts()
67+
common_setup(config=config, setup_db=True, register_mq_exchanges=False)
68+
69+
# Get config values
70+
timestamp = cfg.CONF.timestamp
71+
purge_incomplete = cfg.CONF.purge_incomplete
72+
73+
if not timestamp:
74+
LOG.error("Please supply a timestamp for purging models. Aborting.")
75+
return 1
76+
else:
77+
timestamp = datetime.strptime(timestamp, "%Y-%m-%dT%H:%M:%S.%fZ")
78+
timestamp = timestamp.replace(tzinfo=pytz.UTC)
79+
80+
try:
81+
purge_workflow_executions(
82+
logger=LOG, timestamp=timestamp, purge_incomplete=purge_incomplete
83+
)
84+
except Exception as e:
85+
LOG.exception(six.text_type(e))
86+
return FAILURE_EXIT_CODE
87+
finally:
88+
common_teardown()
89+
90+
return SUCCESS_EXIT_CODE

0 commit comments

Comments
 (0)