Skip to content

Commit d54af64

Browse files
author
Vladimir Kotal
committed
run cleanup command if a command failed or requested break
1 parent 04e1c5c commit d54af64

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

tools/sync/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ where the sync.conf file contents might look like this:
1717
["sudo", "-u", "webservd", "/usr/opengrok/bin/reindex-project.ksh",
1818
"/opengrok/etc/opengrok.conf", "/usr/opengrok/bin"],
1919
["/usr/opengrok/bin/Messages", "-n", "abort", "-t"],
20-
["/scripts/check-indexer-logs.ksh"]]
20+
["/scripts/check-indexer-logs.ksh"]],
21+
"ignore_errors": ["NetBSD-current", "linux-mainline-next"],
22+
"cleanup": ["/usr/opengrok/bin/Messages", "-n", "abort", "-t"]
2123
}
2224
```
2325

tools/sync/commands.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,13 @@ class CommandsBase:
3535
so that it can be passed through Pool.map().
3636
"""
3737

38-
def __init__(self, name, commands):
38+
def __init__(self, name, commands, cleanup=None):
3939
self.name = name
4040
self.commands = commands
4141
self.failed = False
4242
self.retcodes = {}
4343
self.outputs = {}
44+
self.cleanup = cleanup
4445

4546
def __str__(self):
4647
return str(self.name)
@@ -61,7 +62,7 @@ def fill(self, retcodes, outputs, failed):
6162

6263
class Commands(CommandsBase):
6364
def __init__(self, base):
64-
super().__init__(base.name, base.commands)
65+
super().__init__(base.name, base.commands, base.cleanup)
6566

6667
self.logger = logging.getLogger(__name__)
6768
logging.basicConfig()
@@ -88,12 +89,29 @@ def run(self):
8889
if retcode == 2:
8990
self.logger.info("command '{}' requested break".
9091
format(cmd))
92+
self.run_cleanup()
9193
else:
9294
self.logger.info("command '{}' failed with code {}, "
9395
"breaking".format(cmd, retcode))
9496
self.failed = True
97+
self.run_cleanup()
9598
break
9699

100+
def run_cleanup(self):
101+
"""
102+
Call cleanup in case the sequence failed or termination was requested.
103+
"""
104+
if self.cleanup:
105+
self.logger.debug("Running cleanup command '{}'".
106+
format(self.cleanup))
107+
cmd = Command(self.cleanup,
108+
args_subst={"ARG": self.name},
109+
args_append=[self.name], excl_subst=True)
110+
cmd.execute()
111+
if cmd.getretcode() != 0:
112+
self.logger.info("cleanup command '{}' failed with code {}".
113+
format(self.cleanup, cmd.getretcode()))
114+
97115
def check(self, ignore_errors):
98116
"""
99117
Check the output of the commands and perform logging.

tools/sync/sync.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,8 @@ def worker(base):
158158

159159
projects = []
160160
for d in dirs_to_process:
161-
proj = CommandsBase(d, config["commands"])
161+
proj = CommandsBase(d, config.get("commands"),
162+
config.get("cleanup"))
162163
projects.append(proj)
163164

164165
try:

0 commit comments

Comments
 (0)