Impl setting build to fail/continue on limit
If "error_on_build" is set to "true" in the config, then the build will fail if the "log_limit" is reached.
This commit is contained in:
parent
fd86336ee0
commit
ec48b1f419
3 changed files with 56 additions and 37 deletions
|
@ -40,6 +40,12 @@ Change "log\_limit" in the config to a value in bytes if the default of 1 GiB
|
||||||
is too little for your use case (if the size of your output logs extend past 1
|
is too little for your use case (if the size of your output logs extend past 1
|
||||||
GiB somehow).
|
GiB somehow).
|
||||||
|
|
||||||
|
### Error when reaching limit
|
||||||
|
|
||||||
|
"error\_on\_limit" can be set to true/false in the config. If set to true, then
|
||||||
|
the build will fail if the limit is reached. If set to false, then the build
|
||||||
|
will continue even if the limit is reached.
|
||||||
|
|
||||||
# Setting up the AUR Helper
|
# Setting up the AUR Helper
|
||||||
|
|
||||||
The AUR Helper requires several things:
|
The AUR Helper requires several things:
|
||||||
|
|
|
@ -18,6 +18,8 @@ is_timed = true
|
||||||
is_log_timed = true
|
is_log_timed = true
|
||||||
# Default log_limit is 1 GiB
|
# Default log_limit is 1 GiB
|
||||||
log_limit = 1073741824
|
log_limit = 1073741824
|
||||||
|
# If true, then make the build fail if the limit is reached
|
||||||
|
error_on_limit = false
|
||||||
########## END OF MANDATORY VARIABLES
|
########## END OF MANDATORY VARIABLES
|
||||||
|
|
||||||
# Each [[entry]] needs a "name".
|
# Each [[entry]] needs a "name".
|
||||||
|
|
85
update.py
85
update.py
|
@ -1083,41 +1083,44 @@ def cleanup_sccache(chroot: str):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def limited_stream(handle, output_file, log_limit: int):
|
def handle_output_stream(handle, output_file, other_state):
|
||||||
log_count = 0
|
log_count = 0
|
||||||
|
limit_reached = False
|
||||||
while True:
|
while True:
|
||||||
line = handle.readline()
|
line = handle.readline()
|
||||||
if len(line) == 0:
|
if len(line) == 0:
|
||||||
break
|
break
|
||||||
log_count += len(line)
|
|
||||||
if log_count > log_limit:
|
|
||||||
output_file.write(
|
|
||||||
"\nWARNING: Reached log_limit! No longer logging to file!\n"
|
|
||||||
)
|
|
||||||
output_file.flush()
|
|
||||||
break
|
|
||||||
output_file.write(line)
|
|
||||||
output_file.flush()
|
|
||||||
|
|
||||||
|
if not limit_reached:
|
||||||
def prepend_timestamp_stream(handle, output_file, log_limit: int):
|
if other_state["is_log_timed"]:
|
||||||
log_count = 0
|
nowstring = datetime.datetime.now(
|
||||||
while True:
|
datetime.timezone.utc
|
||||||
line = handle.readline()
|
).strftime("%Y-%m-%d_%H-%M-%S_%Z ")
|
||||||
if len(line) == 0:
|
line = nowstring + line
|
||||||
break
|
log_count += len(line)
|
||||||
nowstring = datetime.datetime.now(datetime.timezone.utc).strftime(
|
if log_count > other_state["log_limit"]:
|
||||||
"%Y-%m-%d_%H-%M-%S_%Z "
|
limit_reached = True
|
||||||
)
|
if other_state["error_on_limit"]:
|
||||||
log_count += len(nowstring) + len(line)
|
output_file.write(
|
||||||
if log_count > log_limit:
|
"\nERROR: Reached log_limit! No longer logging to file!\n"
|
||||||
output_file.write(
|
)
|
||||||
"\nWARNING: Reached log_limit! No longer logging to file!\n"
|
output_file.flush()
|
||||||
)
|
log_print(
|
||||||
output_file.flush()
|
"ERROR: Reached log_limit! No longer logging to file!"
|
||||||
break
|
)
|
||||||
output_file.write(nowstring + line)
|
handle.close()
|
||||||
output_file.flush()
|
break
|
||||||
|
else:
|
||||||
|
output_file.write(
|
||||||
|
"\nWARNING: Reached log_limit! No longer logging to file!\n"
|
||||||
|
)
|
||||||
|
output_file.flush()
|
||||||
|
log_print(
|
||||||
|
"WARNING: Reached log_limit! No longer logging to file!"
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
output_file.write(line)
|
||||||
|
output_file.flush()
|
||||||
|
|
||||||
|
|
||||||
def update_pkg_list(
|
def update_pkg_list(
|
||||||
|
@ -1256,16 +1259,12 @@ def update_pkg_list(
|
||||||
stderr=subprocess.PIPE,
|
stderr=subprocess.PIPE,
|
||||||
)
|
)
|
||||||
tout = threading.Thread(
|
tout = threading.Thread(
|
||||||
target=prepend_timestamp_stream
|
target=handle_output_stream,
|
||||||
if other_state["is_log_timed"]
|
args=[p1.stdout, log_stdout, other_state],
|
||||||
else limited_stream,
|
|
||||||
args=[p1.stdout, log_stdout, other_state["log_limit"]],
|
|
||||||
)
|
)
|
||||||
terr = threading.Thread(
|
terr = threading.Thread(
|
||||||
target=prepend_timestamp_stream
|
target=handle_output_stream,
|
||||||
if other_state["is_log_timed"]
|
args=[p1.stderr, log_stderr, other_state],
|
||||||
else limited_stream,
|
|
||||||
args=[p1.stderr, log_stderr, other_state["log_limit"]],
|
|
||||||
)
|
)
|
||||||
|
|
||||||
tout.start()
|
tout.start()
|
||||||
|
@ -1654,6 +1653,7 @@ if __name__ == "__main__":
|
||||||
other_state = {}
|
other_state = {}
|
||||||
other_state["logs_dir"] = None
|
other_state["logs_dir"] = None
|
||||||
other_state["log_limit"] = 1024 * 1024 * 1024
|
other_state["log_limit"] = 1024 * 1024 * 1024
|
||||||
|
other_state["error_on_limit"] = False
|
||||||
if args.pkg and not args.config:
|
if args.pkg and not args.config:
|
||||||
for pkg in args.pkg:
|
for pkg in args.pkg:
|
||||||
pkg_state[pkg] = {}
|
pkg_state[pkg] = {}
|
||||||
|
@ -1804,6 +1804,17 @@ if __name__ == "__main__":
|
||||||
)
|
)
|
||||||
log_print(" {} KiB".format(other_state["log_limit"] / 1024))
|
log_print(" {} KiB".format(other_state["log_limit"] / 1024))
|
||||||
log_print(" {} MiB".format(other_state["log_limit"] / 1024 / 1024))
|
log_print(" {} MiB".format(other_state["log_limit"] / 1024 / 1024))
|
||||||
|
if (
|
||||||
|
"error_on_limit" in d
|
||||||
|
and type(d["error_on_limit"]) is bool
|
||||||
|
and d["error_on_limit"]
|
||||||
|
):
|
||||||
|
other_state["error_on_limit"] = True
|
||||||
|
log_print(
|
||||||
|
'Notice: "error_on_limit" is set to "{}"'.format(
|
||||||
|
other_state["error_on_limit"]
|
||||||
|
)
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
log_print(
|
log_print(
|
||||||
'ERROR: At least "--config" or "--pkg" must be specified',
|
'ERROR: At least "--config" or "--pkg" must be specified',
|
||||||
|
|
Loading…
Reference in a new issue