toymaker.git

commit b8443a169087a6a945ba8ba5e02026a94022d698

Author: Adam <git@apiote.xyz>

run builds in background

 get.sh | 7 ++++++-
 start.sh | 14 ++++++++++----


diff --git a/get.sh b/get.sh
index 568bc92dd164c332e407bb7538da3ceb14e29a0b..ce13dbffe7ed70dc5993759d05a452aec869c318 100644
--- a/get.sh
+++ b/get.sh
@@ -32,11 +32,16 @@
 show_item() {
 	toy=$1
 	item=$2
+	if [ "$(podman inspect "item_${toy}_${item}" 2>/dev/null | jq -r '.[0].State.Status')" = 'exited' ]
+	then
+		podman inspect "item_${toy}_${item}" | jq '.[0].State.ExitCode' > "toys/$toy/$item.exit"
+		podman rm "item_${toy}_${item}" >/dev/null 2>&1
+	fi
 	[ "$item" = 'latest' ] && item=$(find toys/toymaker/ -type d -mindepth 1 -maxdepth 1 | grep -E '[0-9]+' | sort -n | tail -n1 | sed 's|toys/toymaker/||')
 	if [ ! -d "toys/$toy/$item" ]
 	then
 		printf 'n;'
-	elif [ -z "$(cat "toys/$toy/$item.exit")" ]
+	elif [ ! -f "toys/$toy/$item.exit" ]
 	then
 		printf 'r;'
 		cat "toys/$toy/$item.log"




diff --git a/start.sh b/start.sh
index 61aec55d8363bdf45043e92936f08f54601ae4cb..d5304c6577a5b327adc5784daf76c34772a75fde 100644
--- a/start.sh
+++ b/start.sh
@@ -20,12 +20,18 @@ 	lastItem=$(find "toys/$toy/" -type d -maxdepth 1 -mindepth 1 | grep -E '[0-9]+' | sed "s|toys/$toy/||" | sort -n | tail -n 1)
 	lastItem=${lastItem:--1}
 	currentItem=$(( lastItem + 1 ))
 	mkdir "toys/$toy/$currentItem"
+
+	while [ "$(find "toys/$toy/" -type d -maxdepth 1 -mindepth 1 | grep -Ec '[0-9]+')" -gt 6 ]
+	do
+		earliestItem=$(find "toys/$toy/" -type d -maxdepth 1 -mindepth 1 | grep -E '[0-9]+' | sed "s|toys/$toy/||" | sort -n | head -n 1)
+		rm -rf "toys/$toy/$earliestItem" "toys/$toy/$earliestItem.log" "toys/$toy/$earliestItem.exit"
+	done
+
 	rm -r "toys/$toy/.lock"
 
-	(
-	podman run --name "item_${toy}_$item" --rm "toy_$toy" "$item" >"toys/$toy/$currentItem.log" 2>&1
-	echo $? >"toys/$toy/$currentItem.exit"
-	) &
+	touch "toys/$toy/$currentItem.log"
+	# shellcheck disable=SC2154
+	podman run -d --timeout 86400 --log-opt=path="$docroot/toys/$toy/$currentItem.log" --name "item_${toy}_$currentItem" "toy_$toy" "$currentItem" >/dev/null 2>&1
 
 	printf "%s" "$currentItem"
 }