replace curl --retry with bash builtins (#101)

This commit is contained in:
Felix Lohmeier 2023-04-14 12:34:04 +02:00 committed by GitHub
parent 56272613f2
commit 98ef70e29b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 114 additions and 181 deletions

259
orcli
View File

@ -1,5 +1,5 @@
#!/usr/bin/env bash
# This script was generated by bashly 0.9.4 (https://bashly.dannyb.co)
# This script was generated by bashly 1.0.3 (https://bashly.dannyb.co)
# Modifying it manually is not recommended
# :wrapper.bash3_bouncer
@ -139,11 +139,6 @@ orcli_delete_usage() {
if [[ -n $long_usage ]]; then
printf "%s\n" "Options:"
# :command.usage_fixed_flags
printf " %s\n" "--help, -h"
printf " Show this help\n"
echo
# :command.usage_flags
# :flag.usage
printf " %s\n" "--force, -f"
@ -155,6 +150,11 @@ orcli_delete_usage() {
printf " suppress log output, print errors only\n"
echo
# :command.usage_fixed_flags
printf " %s\n" "--help, -h"
printf " Show this help\n"
echo
# :command.usage_args
printf "%s\n" "Arguments:"
@ -229,11 +229,6 @@ orcli_import_csv_usage() {
if [[ -n $long_usage ]]; then
printf "%s\n" "Options:"
# :command.usage_fixed_flags
printf " %s\n" "--help, -h"
printf " Show this help\n"
echo
# :command.usage_flags
# :flag.usage
printf " %s\n" "--separator SEPARATOR"
@ -331,6 +326,11 @@ orcli_import_csv_usage() {
printf " suppress log output, print errors only\n"
echo
# :command.usage_fixed_flags
printf " %s\n" "--help, -h"
printf " Show this help\n"
echo
# :command.usage_args
printf "%s\n" "Arguments:"
@ -373,11 +373,6 @@ orcli_import_tsv_usage() {
if [[ -n $long_usage ]]; then
printf "%s\n" "Options:"
# :command.usage_fixed_flags
printf " %s\n" "--help, -h"
printf " Show this help\n"
echo
# :command.usage_flags
# :flag.usage
printf " %s\n" "--blankCellsAsStrings"
@ -469,6 +464,11 @@ orcli_import_tsv_usage() {
printf " suppress log output, print errors only\n"
echo
# :command.usage_fixed_flags
printf " %s\n" "--help, -h"
printf " Show this help\n"
echo
# :command.usage_args
printf "%s\n" "Arguments:"
@ -613,17 +613,17 @@ orcli_transform_usage() {
if [[ -n $long_usage ]]; then
printf "%s\n" "Options:"
# :command.usage_fixed_flags
printf " %s\n" "--help, -h"
printf " Show this help\n"
echo
# :command.usage_flags
# :flag.usage
printf " %s\n" "--quiet, -q"
printf " suppress log output, print errors only\n"
echo
# :command.usage_fixed_flags
printf " %s\n" "--help, -h"
printf " Show this help\n"
echo
# :command.usage_args
printf "%s\n" "Arguments:"
@ -704,11 +704,6 @@ orcli_export_tsv_usage() {
if [[ -n $long_usage ]]; then
printf "%s\n" "Options:"
# :command.usage_fixed_flags
printf " %s\n" "--help, -h"
printf " Show this help\n"
echo
# :command.usage_flags
# :flag.usage
printf " %s\n" "--facets FACETS"
@ -732,6 +727,11 @@ orcli_export_tsv_usage() {
printf " suppress log output, print errors only\n"
echo
# :command.usage_fixed_flags
printf " %s\n" "--help, -h"
printf " Show this help\n"
echo
# :command.usage_args
printf "%s\n" "Arguments:"
@ -772,11 +772,6 @@ orcli_export_template_usage() {
if [[ -n $long_usage ]]; then
printf "%s\n" "Options:"
# :command.usage_fixed_flags
printf " %s\n" "--help, -h"
printf " Show this help\n"
echo
# :command.usage_flags
# :flag.usage
printf " %s\n" "--separator SEPARATOR"
@ -822,6 +817,11 @@ orcli_export_template_usage() {
printf " suppress log output, print errors only\n"
echo
# :command.usage_fixed_flags
printf " %s\n" "--help, -h"
printf " Show this help\n"
echo
# :command.usage_args
printf "%s\n" "Arguments:"
@ -869,11 +869,6 @@ orcli_run_usage() {
if [[ -n $long_usage ]]; then
printf "%s\n" "Options:"
# :command.usage_fixed_flags
printf " %s\n" "--help, -h"
printf " Show this help\n"
echo
# :command.usage_flags
# :flag.usage
printf " %s\n" "--memory RAM"
@ -897,6 +892,11 @@ orcli_run_usage() {
printf " suppress log output, print errors only\n"
echo
# :command.usage_fixed_flags
printf " %s\n" "--help, -h"
printf " Show this help\n"
echo
# :command.usage_args
printf "%s\n" "Arguments:"
@ -943,8 +943,8 @@ normalize_input() {
}
# :command.inspect_args
inspect_args() {
readarray -t sorted_keys < <(printf '%s\n' "${!args[@]}" | sort)
if ((${#args[@]})); then
readarray -t sorted_keys < <(printf '%s\n' "${!args[@]}" | sort)
echo args:
for k in "${sorted_keys[@]}"; do echo "- \${args[$k]} = ${args[$k]}"; done
else
@ -959,6 +959,14 @@ inspect_args() {
echo "- \${other_args[$i]} = ${other_args[$i]}"
done
fi
if ((${#deps[@]})); then
readarray -t sorted_keys < <(printf '%s\n' "${!deps[@]}" | sort)
echo
echo deps:
for k in "${sorted_keys[@]}"; do echo "- \${deps[$k]} = ${deps[$k]}"; done
fi
}
# :command.user_lib
@ -1556,14 +1564,20 @@ orcli_test_command() {
# update trap to kill OpenRefine on error or exit
trap '{ rm -rf "$OPENREFINE_TMPDIR"; rm -rf /tmp/jetty-127_0_0_1-3333*; kill -9 "$OPENREFINE_PID"; }' 0 2 3 15
# wait until OpenRefine is running (timeout 15s + 15s)
if ! curl -fs --retry 15 --retry-connrefused --retry-delay 1 "${OPENREFINE_URL}/command/core/get-version" &>/dev/null; then
# try again with IPv4 only
if ! curl -fs -4 --retry 15 --retry-connrefused --retry-delay 1 "${OPENREFINE_URL}/command/core/get-version" &>/dev/null; then
error "starting OpenRefine server failed!"
# wait until OpenRefine is running (timeout 20s)
ready="n"
for i in {1..20}; do
if curl -fs "${OPENREFINE_URL}/command/core/get-version" &>/dev/null; then
ready="y"
break
else
sleep 1
fi
else
done
if [[ "$ready" == "y" ]]; then
log "started OpenRefine with tmp workspace ${OPENREFINE_TMPDIR}"
else
error "starting OpenRefine server failed!"
fi
# execute tests in subshell
@ -1845,14 +1859,20 @@ orcli_run_command() {
# update trap to kill OpenRefine on error or exit
trap '{ rm -rf "$OPENREFINE_TMPDIR"; rm -rf /tmp/jetty-127_0_0_1-${OPENREFINE_URL##*:}*; kill -9 "$OPENREFINE_PID"; }' 0 2 3 15
# wait until OpenRefine is running (timeout 15s + 15s)
if ! curl -fs --retry 15 --retry-connrefused --retry-delay 1 "${OPENREFINE_URL}/command/core/get-version" &>/dev/null; then
# try again with IPv4 only
if ! curl -fs -4 --retry 15 --retry-connrefused --retry-delay 1 "${OPENREFINE_URL}/command/core/get-version" &>/dev/null; then
error "starting OpenRefine server failed!"
# wait until OpenRefine is running (timeout 20s)
ready="n"
for i in {1..20}; do
if curl -fs "${OPENREFINE_URL}/command/core/get-version" &>/dev/null; then
ready="y"
break
else
sleep 1
fi
else
done
if [[ "$ready" == "y" ]]; then
log "started OpenRefine" "port: ${args[--port]}" "memory: ${args[--memory]}" "tmpdir: ${OPENREFINE_TMPDIR}" "pid: ${OPENREFINE_PID}"
else
error "starting OpenRefine server failed!"
fi
# execute script(s) in subshell
@ -1929,13 +1949,17 @@ parse_requirements() {
export OPENREFINE_URL="${OPENREFINE_URL:-http://localhost:3333}"
# :command.dependencies_filter
if ! command -v curl >/dev/null 2>&1; then
if command -v curl >/dev/null 2>&1; then
deps['curl']="$(command -v curl | head -n1)"
else
printf "missing dependency: curl\n" >&2
printf "%s\n" "https://curl.se" >&2
exit 1
fi
if ! command -v jq >/dev/null 2>&1; then
if command -v jq >/dev/null 2>&1; then
deps['jq']="$(command -v jq | head -n1)"
else
printf "missing dependency: jq\n" >&2
printf "%s\n" "https://github.com/stedolan/jq" >&2
exit 1
@ -3360,7 +3384,7 @@ orcli_export_template_parse_requirements() {
[[ -n ${args['--encoding']:-} ]] || args['--encoding']="UTF-8"
# :command.whitelist_filter
if [[ ! ${args['--mode']} =~ ^(rows|records)$ ]]; then
if [[ ${args['--mode']} ]] && [[ ! ${args['--mode']} =~ ^(rows|records)$ ]]; then
printf "%s\n" "--mode must be one of: rows, records" >&2
exit 1
fi
@ -3483,129 +3507,26 @@ initialize() {
# :command.run
run() {
declare -A args=()
declare -A deps=()
declare -a other_args=()
declare -a input=()
normalize_input "$@"
parse_requirements "${input[@]}"
case "$action" in
"completions")
if [[ ${args['--help']:-} ]]; then
long_usage=yes
orcli_completions_usage
else
orcli_completions_command
fi
;;
"delete")
if [[ ${args['--help']:-} ]]; then
long_usage=yes
orcli_delete_usage
else
orcli_delete_command
fi
;;
"import")
if [[ ${args['--help']:-} ]]; then
long_usage=yes
orcli_import_usage
else
orcli_import_command
fi
;;
"import csv")
if [[ ${args['--help']:-} ]]; then
long_usage=yes
orcli_import_csv_usage
else
orcli_import_csv_command
fi
;;
"import tsv")
if [[ ${args['--help']:-} ]]; then
long_usage=yes
orcli_import_tsv_usage
else
orcli_import_tsv_command
fi
;;
"list")
if [[ ${args['--help']:-} ]]; then
long_usage=yes
orcli_list_usage
else
orcli_list_command
fi
;;
"info")
if [[ ${args['--help']:-} ]]; then
long_usage=yes
orcli_info_usage
else
orcli_info_command
fi
;;
"test")
if [[ ${args['--help']:-} ]]; then
long_usage=yes
orcli_test_usage
else
orcli_test_command
fi
;;
"transform")
if [[ ${args['--help']:-} ]]; then
long_usage=yes
orcli_transform_usage
else
orcli_transform_command
fi
;;
"export")
if [[ ${args['--help']:-} ]]; then
long_usage=yes
orcli_export_usage
else
orcli_export_command
fi
;;
"export tsv")
if [[ ${args['--help']:-} ]]; then
long_usage=yes
orcli_export_tsv_usage
else
orcli_export_tsv_command
fi
;;
"export template")
if [[ ${args['--help']:-} ]]; then
long_usage=yes
orcli_export_template_usage
else
orcli_export_template_command
fi
;;
"run")
if [[ ${args['--help']:-} ]]; then
long_usage=yes
orcli_run_usage
else
orcli_run_command
fi
;;
"completions") orcli_completions_command ;;
"delete") orcli_delete_command ;;
"import") orcli_import_command ;;
"import csv") orcli_import_csv_command ;;
"import tsv") orcli_import_tsv_command ;;
"list") orcli_list_command ;;
"info") orcli_info_command ;;
"test") orcli_test_command ;;
"transform") orcli_transform_command ;;
"export") orcli_export_command ;;
"export tsv") orcli_export_tsv_command ;;
"export template") orcli_export_template_command ;;
"run") orcli_run_command ;;
esac
}

View File

@ -54,14 +54,20 @@ OPENREFINE_PID="$!"
# update trap to kill OpenRefine on error or exit
trap '{ rm -rf "$OPENREFINE_TMPDIR"; rm -rf /tmp/jetty-127_0_0_1-${OPENREFINE_URL##*:}*; kill -9 "$OPENREFINE_PID"; }' 0 2 3 15
# wait until OpenRefine is running (timeout 15s + 15s)
if ! curl -fs --retry 15 --retry-connrefused --retry-delay 1 "${OPENREFINE_URL}/command/core/get-version" &>/dev/null; then
# try again with IPv4 only
if ! curl -fs -4 --retry 15 --retry-connrefused --retry-delay 1 "${OPENREFINE_URL}/command/core/get-version" &>/dev/null; then
error "starting OpenRefine server failed!"
# wait until OpenRefine is running (timeout 20s)
ready="n"
for i in {1..20}; do
if curl -fs "${OPENREFINE_URL}/command/core/get-version" &>/dev/null; then
ready="y"
break
else
sleep 1
fi
else
done
if [[ "$ready" == "y" ]]; then
log "started OpenRefine" "port: ${args[--port]}" "memory: ${args[--memory]}" "tmpdir: ${OPENREFINE_TMPDIR}" "pid: ${OPENREFINE_PID}"
else
error "starting OpenRefine server failed!"
fi
# execute script(s) in subshell

View File

@ -34,14 +34,20 @@ OPENREFINE_PID="$!"
# update trap to kill OpenRefine on error or exit
trap '{ rm -rf "$OPENREFINE_TMPDIR"; rm -rf /tmp/jetty-127_0_0_1-3333*; kill -9 "$OPENREFINE_PID"; }' 0 2 3 15
# wait until OpenRefine is running (timeout 15s + 15s)
if ! curl -fs --retry 15 --retry-connrefused --retry-delay 1 "${OPENREFINE_URL}/command/core/get-version" &>/dev/null; then
# try again with IPv4 only
if ! curl -fs -4 --retry 15 --retry-connrefused --retry-delay 1 "${OPENREFINE_URL}/command/core/get-version" &>/dev/null; then
error "starting OpenRefine server failed!"
# wait until OpenRefine is running (timeout 20s)
ready="n"
for i in {1..20}; do
if curl -fs "${OPENREFINE_URL}/command/core/get-version" &>/dev/null; then
ready="y"
break
else
sleep 1
fi
else
done
if [[ "$ready" == "y" ]]; then
log "started OpenRefine with tmp workspace ${OPENREFINE_TMPDIR}"
else
error "starting OpenRefine server failed!"
fi
# execute tests in subshell