From 90d16b32b3e159228338375f63358f6ace8817e6 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 22 Mar 2026 14:57:56 +0000 Subject: [PATCH 1/2] Initial plan From 2276aeafb29cff8cbe1e1e5805927842827aa480 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 22 Mar 2026 15:01:22 +0000 Subject: [PATCH 2/2] Fix code review feedback: require_command checks, temp file cleanup, batch MySQL inserts Co-authored-by: sfreeman422 <16405652+sfreeman422@users.noreply.github.com> Agent-Logs-Url: https://github.com/dev-chat/mocker/sessions/1c571688-b133-4945-9edc-a6d11e23df1d --- packages/jobs/fun-fact-job/script.sh | 8 +++++++- packages/jobs/health-job/script.sh | 13 +++++++++++++ packages/jobs/pricing-job/script.sh | 12 ++++++++++-- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/packages/jobs/fun-fact-job/script.sh b/packages/jobs/fun-fact-job/script.sh index ed483e63..f48fb95f 100755 --- a/packages/jobs/fun-fact-job/script.sh +++ b/packages/jobs/fun-fact-job/script.sh @@ -337,7 +337,13 @@ send_slack_message() { --header "Authorization: Bearer ${MUZZLE_BOT_TOKEN}" \ --header 'Content-Type: application/json; charset=utf-8' \ --data "${payload}" \ - https://slack.com/api/chat.postMessage) + https://slack.com/api/chat.postMessage || true) + + if [[ -z "${response_code:-}" ]]; then + echo "Slack API request failed: curl did not complete successfully" >&2 + rm -f "${response_file}" + return 1 + fi if [[ "${response_code}" != '200' ]] || ! jq -e '.ok == true' "${response_file}" >/dev/null 2>&1; then cat "${response_file}" >&2 diff --git a/packages/jobs/health-job/script.sh b/packages/jobs/health-job/script.sh index 5b9308d7..fa26bfd8 100755 --- a/packages/jobs/health-job/script.sh +++ b/packages/jobs/health-job/script.sh @@ -10,6 +10,15 @@ fi PATH=/usr/local/bin:/usr/bin:/bin:${PATH:-} +require_command() { + local command_name="$1" + + if ! command -v "${command_name}" >/dev/null 2>&1; then + echo "Missing required command: ${command_name}" >&2 + exit 1 + fi +} + HEALTH_URL="${HEALTH_URL:-http://127.0.0.1:3000/health}" SLACK_CHANNEL="${SLACK_CHANNEL:-#muzzlefeedback}" SLACK_MESSAGE=':this-is-fine: `Moonbeam is experiencing some technical difficulties at the moment.` :this-is-fine:' @@ -89,6 +98,10 @@ check_health() { } main() { + require_command curl + require_command grep + require_command mktemp + if check_health; then exit 0 fi diff --git a/packages/jobs/pricing-job/script.sh b/packages/jobs/pricing-job/script.sh index 333e0251..0fbc1c6f 100755 --- a/packages/jobs/pricing-job/script.sh +++ b/packages/jobs/pricing-job/script.sh @@ -96,6 +96,7 @@ main() { local price_pct local price local median_rep + local sql_batch local -a teams local -a items local row @@ -125,18 +126,25 @@ main() { median_rep=$(calculate_median_rep) + sql_batch="" for team_id in "${teams[@]}"; do [[ -n "${team_id}" ]] || continue for item_row in "${items[@]}"; do IFS=$'\t' read -r item_id price_pct <<<"${item_row}" price=$(awk -v median="${median_rep}" -v pct="${price_pct}" 'BEGIN { printf "%.15f", median * pct }') - mysql_query "INSERT INTO price(itemId, teamId, price, itemIdId) VALUES(${item_id}, '$(sql_escape "${team_id}")', ${price}, ${item_id});" >/dev/null + sql_batch+="INSERT INTO price(itemId, teamId, price, itemIdId) VALUES(${item_id}, '$(sql_escape "${team_id}")', ${price}, ${item_id});"$'\n' done - echo "Completed update for ${team_id}" + echo "Queued update for ${team_id}" done + if [[ -n "${sql_batch}" ]]; then + echo 'Executing batch price inserts...' + mysql_query "START TRANSACTION; +${sql_batch}COMMIT;" || { echo 'Batch insert failed; transaction has been rolled back' >&2; return 1; } + fi + echo "Completed job in $(( $(date +%s) - start_time )) seconds!" }