s+ow: do first sleep 30 in script itself if SPOW_CRON=y (#50)
* deps: add shfmt and shellcheck * s+ow: also add time took to run information
This commit is contained in:
parent
dd5d95f21f
commit
30d23d61cc
|
@ -2,10 +2,14 @@
|
|||
"packages": [
|
||||
"python311@latest",
|
||||
"python311Packages.ipykernel@latest",
|
||||
"poetry@latest"
|
||||
"poetry@latest",
|
||||
"shfmt@latest",
|
||||
"shellcheck@latest"
|
||||
],
|
||||
"shell": {
|
||||
"init_hook": ["poetry install"]
|
||||
"init_hook": [
|
||||
"poetry install"
|
||||
]
|
||||
},
|
||||
"nixpkgs": {
|
||||
"commit": "f80ac848e3d6f0c12c52758c0f25c10c97ca3b62"
|
||||
|
|
40
devbox.lock
40
devbox.lock
|
@ -62,6 +62,46 @@
|
|||
"store_path": "/nix/store/3kqcf56q2q46hj0g5n4rxzzy1c9vdiqa-python3.11-ipykernel-6.21.2"
|
||||
}
|
||||
}
|
||||
},
|
||||
"shellcheck@latest": {
|
||||
"last_modified": "2023-10-25T20:49:13Z",
|
||||
"resolved": "github:NixOS/nixpkgs/75a52265bda7fd25e06e3a67dee3f0354e73243c#shellcheck",
|
||||
"source": "devbox-search",
|
||||
"version": "0.9.0",
|
||||
"systems": {
|
||||
"aarch64-darwin": {
|
||||
"store_path": "/nix/store/w3i70rjj7nhz211hp172g5i6f8f7kp1j-shellcheck-0.9.0-bin"
|
||||
},
|
||||
"aarch64-linux": {
|
||||
"store_path": "/nix/store/4fapanq6k3x6pb990mbfcnj0cwzsizr7-shellcheck-0.9.0-bin"
|
||||
},
|
||||
"x86_64-darwin": {
|
||||
"store_path": "/nix/store/gkv79r6iiys1k9d523slnz4k7vf99xcl-shellcheck-0.9.0-bin"
|
||||
},
|
||||
"x86_64-linux": {
|
||||
"store_path": "/nix/store/sfc6nh6a2q1a71dz39rm4y5c7az1s3di-shellcheck-0.9.0-bin"
|
||||
}
|
||||
}
|
||||
},
|
||||
"shfmt@latest": {
|
||||
"last_modified": "2023-10-25T20:49:13Z",
|
||||
"resolved": "github:NixOS/nixpkgs/75a52265bda7fd25e06e3a67dee3f0354e73243c#shfmt",
|
||||
"source": "devbox-search",
|
||||
"version": "3.7.0",
|
||||
"systems": {
|
||||
"aarch64-darwin": {
|
||||
"store_path": "/nix/store/3nfimx4z0nbxdkkshqpxzrh73llm57vk-shfmt-3.7.0"
|
||||
},
|
||||
"aarch64-linux": {
|
||||
"store_path": "/nix/store/2qk1vvq18nfvjjf1rz4kdxbjd6rayw6a-shfmt-3.7.0"
|
||||
},
|
||||
"x86_64-darwin": {
|
||||
"store_path": "/nix/store/1rigank4nlkq41dzqvp1di4hd628wp02-shfmt-3.7.0"
|
||||
},
|
||||
"x86_64-linux": {
|
||||
"store_path": "/nix/store/lv02gfaqb60xl8a3x55g6s2s0yqrrpp5-shfmt-3.7.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
57
s+ow
57
s+ow
|
@ -211,15 +211,13 @@ notify() {
|
|||
}
|
||||
|
||||
notify_end() {
|
||||
# $1 is s+ow status (0, 1, 2)
|
||||
# $2 is termux-location run number
|
||||
# $3 is sent type (0, 1, 2)
|
||||
# $4 is sharetext
|
||||
# $1 is done tuple
|
||||
# $2 is sharetext
|
||||
termux-notification \
|
||||
--priority "min" \
|
||||
--id "s+ow" \
|
||||
--title "surplus on wheels" \
|
||||
--content "$(printf 'Run has finished. (%d, %d, %d)\n\n%s' "$1" "$2" "$3" "$4")"
|
||||
--content "$(printf 'Run has finished. %s\n\n%s' "$1" "$2")"
|
||||
}
|
||||
|
||||
# program functions
|
||||
|
@ -233,6 +231,21 @@ run() {
|
|||
printf "[run! stdout (%s)]\n" "$(date)" >>"$SPOW_SESH_OUT"
|
||||
printf "[run! stderr (%s)]\n" "$(date)" >>"$SPOW_SESH_ERR"
|
||||
|
||||
time_run_start="$(date +%s)"
|
||||
|
||||
# if cron: wait until its the new hour
|
||||
if [ -n "$SPOW_CRON" ]; then
|
||||
notify "Waiting for the 30th second to pass..."
|
||||
printf "waiting for the 30th second to pass...\n"
|
||||
while [ "$(date +'%S')" -lt 30 ]; do
|
||||
printf " $(date)\n"
|
||||
sleep 1
|
||||
done
|
||||
printf "proceeding\n"
|
||||
fi
|
||||
|
||||
time_locate_start="$(date +%s)"
|
||||
|
||||
# termux-location
|
||||
location=""
|
||||
for locate_run in 1 2 3; do # run three times in case :p
|
||||
|
@ -252,6 +265,11 @@ run() {
|
|||
fi
|
||||
done
|
||||
|
||||
time_locate_end="$(date +%s)"
|
||||
time_locate=$((time_locate_end - time_locate_start))
|
||||
|
||||
time_surplus_start="$(date +%s)"
|
||||
|
||||
# surplus
|
||||
printf "running surplus... "
|
||||
notify "Running surplus -td $location"
|
||||
|
@ -270,16 +288,22 @@ run() {
|
|||
printf "skipped\n"
|
||||
fi
|
||||
|
||||
time_surplus_end="$(date +%s)"
|
||||
time_surplus=$((time_surplus_end - time_surplus_start))
|
||||
|
||||
# if cron: wait until its the new hour
|
||||
if [ -n "$SPOW_CRON" ]; then
|
||||
notify "Waiting for the new hour..."
|
||||
printf "waiting until the new hour...\n"
|
||||
while [ "$(date +'%M')" -eq 59 ]; do
|
||||
printf " $(date)\n"
|
||||
sleep 1
|
||||
done
|
||||
printf "done\n"
|
||||
printf "proceeding\n"
|
||||
fi
|
||||
|
||||
time_sendmsg_start="$(date +%s)"
|
||||
|
||||
# mdtest/send message
|
||||
printf "sending message(s)... "
|
||||
notify "Sending message(s)"
|
||||
|
@ -308,18 +332,24 @@ run() {
|
|||
printf "using fallback... \n"
|
||||
fi
|
||||
|
||||
# send done info except
|
||||
printf "(%d, %d, %d) [lc:%ds sp:%ds]\n" "$status" "$locate_run" "$sent_type" "$time_locate" "$time_surplus" >>"$SPOW_SESH_ERR"
|
||||
|
||||
send "$JID_NOMINAL_TARGET" "$sharetext"
|
||||
send "$JID_ERRORED_TARGET" "$(cat "$SPOW_SESH_ERR")"
|
||||
fi
|
||||
|
||||
done_msg="$(printf "done (%d, %d, %d)\n" "$status" "$locate_run" "$sent_type")"
|
||||
echo "$done_msg"
|
||||
echo "$done_msg" >>"$SPOW_SESH_ERR"
|
||||
time_sendmsg_end="$(date +%s)"
|
||||
time_sendmsg=$((time_sendmsg_end - time_sendmsg_start))
|
||||
|
||||
time_run_end="$(date +%s)"
|
||||
time_run=$((time_run_end - time_run_start))
|
||||
|
||||
done_info="$(printf "(%d, %d, %d) [lc:%ds sp:%ds sm:%ds - %ds]\n" "$status" "$locate_run" "$sent_type" "$time_locate" "$time_surplus" "$time_sendmsg" "$time_run")"
|
||||
echo "done $done_info" | tee -a "$SPOW_SESH_ERR"
|
||||
|
||||
# cleanup
|
||||
printf "%s\n\n" "$(cat "$SPOW_SESH_OUT")" >>"$SPOW_WEEK_OUT"
|
||||
printf "%s\n\n" "$(cat "$SPOW_SESH_ERR")" >>"$SPOW_WEEK_ERR"
|
||||
notify_end "$status" "$locate_run" "$sent_type" "$sharetext"
|
||||
notify_end "$done_info" "$sharetext"
|
||||
}
|
||||
|
||||
# script entry
|
||||
|
@ -344,3 +374,6 @@ choices
|
|||
$0
|
||||
run surplus on wheels normally"
|
||||
fi
|
||||
|
||||
printf "%s\n\n" "$(cat "$SPOW_SESH_OUT")" >>"$SPOW_WEEK_OUT"
|
||||
printf "%s\n\n" "$(cat "$SPOW_SESH_ERR")" >>"$SPOW_WEEK_ERR"
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#!/bin/sh
|
||||
sv-enable crond
|
||||
printf "59 * * * *\t(sleep 30; JID_NOMINAL_TARGET=\"\" JID_ERRORED_TARGET=\"\" LOCATION_PRIORITISE_NETWORK=n SPOW_CRON=y ~/.local/bin/s+ow)\n" | crontab -
|
||||
printf "59 * * * *\tJID_NOMINAL_TARGET=\"\" JID_ERRORED_TARGET=\"\" LOCATION_PRIORITISE_NETWORK=n SPOW_CRON=y ~/.local/bin/s+ow\n" | crontab -
|
||||
crontab -e
|
||||
|
|
Loading…
Reference in a new issue