Skip to content

Commit

Permalink
post-transaction-actions: make execution order predictable
Browse files Browse the repository at this point in the history
  • Loading branch information
galaxy4public authored and lukash committed Nov 13, 2020
1 parent 7d331cb commit af1a055
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
7 changes: 6 additions & 1 deletion doc/post-transaction-actions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,12 @@ Each non-comment line defines an action and consists of three items separated by
The shell command will be evaluated for each package that matched the ``package_filter`` and
the ``transaction_state``. However, after variable substitution, any duplicate commands will be
removed and each command will only be executed once per transaction. The order of execution
of the commands may differ from the order of packages in the transaction.
of the commands follows the order in the action files, but may differ from the order of
packages in the transaction. In other words, when you define several action lines for the
same ``package_filter`` these lines will be executed in the order they were defined in the
action file when the ``package_filter`` matches a package during the ``trasaction_state`` state.
However, the order of when a particular ``package_filter`` is invoked depends on the position
of the corresponding package in the transaction.

An example action file:
^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
8 changes: 6 additions & 2 deletions plugins/post-transaction-actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def transaction(self):
out_ts_items.append(ts_item)
all_ts_items.append(ts_item)

commands_to_run = set()
commands_to_run = []
for (a_key, a_state, a_command) in action_tuples:
if a_state == "in":
ts_items = in_ts_items
Expand All @@ -141,7 +141,11 @@ def transaction(self):
if tsi.pkg == pkg and tsi.pkg.reponame == pkg.reponame]
ts_item = ts_item_list[0]
command = self._replace_vars(ts_item, a_command)
commands_to_run.add(command)
commands_to_run.append(command)

# de-dup the list
seen = set()
commands_to_run = [x for x in commands_to_run if x not in seen and not seen.add(x)]

for command in commands_to_run:
try:
Expand Down

0 comments on commit af1a055

Please sign in to comment.