diff options
author | Erich Eckner <git@eckner.net> | 2019-07-15 12:19:18 +0200 |
---|---|---|
committer | Erich Eckner <git@eckner.net> | 2019-07-15 12:19:18 +0200 |
commit | d022cc831de17d10bd3fed46b38c3dac3cd1341f (patch) | |
tree | 40af17ae92c9ae42d8690d9d3a8922a21a0de8ff /bin | |
parent | a80cb33621fbf37a64fe39b550ae25088588149c (diff) | |
download | builder-d022cc831de17d10bd3fed46b38c3dac3cd1341f.tar.xz |
bin/slave-build-connect: save exit_code and duration of run commands
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/slave-build-connect | 57 |
1 files changed, 39 insertions, 18 deletions
diff --git a/bin/slave-build-connect b/bin/slave-build-connect index 5460b7e..13fcf18 100755 --- a/bin/slave-build-connect +++ b/bin/slave-build-connect @@ -44,25 +44,46 @@ if [ "x${SSH_ORIGINAL_COMMAND%% *}" = 'xget-assignment' ] || \ slave_id="${infos%% *}" operator="${infos#* }" - # shellcheck disable=SC2016 - { - printf 'INSERT IGNORE INTO `ssh_log` (`build_slave`,`action`,`parameters`)' - printf ' VALUES (%s' \ - "${slave_id}" - printf ',from_base64("%s")' \ - "$( - printf '%s' "${SSH_ORIGINAL_COMMAND%% *}" | \ - base64 -w0 - )" \ - "$( - printf '%s' "${SSH_ORIGINAL_COMMAND#* }" | \ - base64 -w0 - )" - printf ');\n' - } | \ - mysql_run_query 'unimportant' + ssh_log_id=$( + # shellcheck disable=SC2016 + { + printf 'INSERT IGNORE INTO `ssh_log` (`build_slave`,`action`,`parameters`)' + printf ' VALUES (%s' \ + "${slave_id}" + printf ',from_base64("%s")' \ + "$( + printf '%s' "${SSH_ORIGINAL_COMMAND%% *}" | \ + base64 -w0 + )" \ + "$( + printf '%s' "${SSH_ORIGINAL_COMMAND#* }" | \ + base64 -w0 + )" + printf ');\n' + printf 'SELECT LAST_INSERT_ID();\n' + } | \ + mysql_run_query 'unimportant' + ) + exit_code=0 + + slave="$1" slave_id="${slave_id}" operator="${operator}" SKIP_COMMAND_LOG=1 /bin/sh -c "${base_dir}/bin/${SSH_ORIGINAL_COMMAND}" \ + || exit_code=$? + + if [ -n "${ssh_log_id}" ]; then + # shellcheck disable=SC2016 + { + printf 'UPDATE `ssh_log`' + printf ' SET `ssh_log`.`duration`=TIME_TO_SEC(TIMEDIFF(NOW(),`ssh_log`.`date`)),' + printf '`ssh_log`.`exit_code`=%s' \ + "${exit_code}" + printf ' WHERE `ssh_log`.`id`=%s' \ + "${ssh_log_id}" + printf ';\n' + } | \ + mysql_run_query 'unimportant' + fi - slave="$1" slave_id="${slave_id}" operator="${operator}" SKIP_COMMAND_LOG=1 /bin/sh -c "${base_dir}/bin/${SSH_ORIGINAL_COMMAND}" + exit ${exit_code} else |