Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
Diffstat (limited to 'bin')
-rwxr-xr-xbin/get-assignment113
1 files changed, 69 insertions, 44 deletions
diff --git a/bin/get-assignment b/bin/get-assignment
index fc38a16..f4ed82a 100755
--- a/bin/get-assignment
+++ b/bin/get-assignment
@@ -111,53 +111,78 @@ clean_up() {
tmp_dir=$(mktemp -d 'tmp.get-assignment.XXXXXXXXXX' --tmpdir)
trap clean_up EXIT
-# TODO: binary package $x it is not a yet-to-be-built dependency of
-# package $y if $x and $y are built by the same build_assignment!
+# if we're building something already, hand it out (again)
+currently_building=$(
+ # shellcheck disable=SC2016
+ {
+ printf 'SELECT'
+ printf ' `package_sources`.`%s`,' \
+ 'pkgbase' \
+ 'git_revision' \
+ 'mod_git_revision'
+ printf '`upstream_repositories`.`name`'
+ printf ' FROM `build_slaves`'
+ printf ' JOIN `%s` ON `%s`.`id`=`%s`.`%s`' \
+ 'build_assignments' 'build_assignments' 'build_slaves' 'currently_building' \
+ 'package_sources' 'package_sources' 'build_assignments' 'package_source' \
+ 'upstream_repositories' 'upstream_repositories' 'package_sources' 'upstream_package_repository'
+ printf ' WHERE `build_slaves`.`name`=from_base64("%s")' \
+ "$(printf '%s' "${slave}" | base64 -w0)"
+ printf ' LIMIT 1;\n'
+ } | \
+ ${mysql_command} --batch --raw | \
+ sed '1d'
+)
+
+if [ -n "${currently_building}" ]; then
+ # shellcheck disable=SC2086
+ hand_out_assignment ${currently_building}
+fi
-# shellcheck disable=SC2016
-{
- printf 'SELECT'
- printf ' COALESCE('
+# packages with all dependencies met, ordered by number of failed trials
+next_building=$(
+ # shellcheck disable=SC2016
+ {
+ printf 'SELECT'
printf '('
- printf 'SELECT'
- printf ' `build_slaves`.`currently_building`'
+ printf 'SELECT COUNT(*)'
+ printf ' FROM `failed_builds`'
+ printf ' WHERE `failed_builds`.`build_assignment`=`build_assignments`.`id`'
+ printf ') AS `trials`,'
+ printf '`package_sources`.`%s`,' \
+ 'pkgbase' \
+ 'git_revision' \
+ 'mod_git_revision'
+ printf '`upstream_repositories`.`name`'
+ printf ' FROM `binary_packages`'
+ printf ' JOIN `%s` ON `%s`.`id`=`%s`.`%s`' \
+ 'build_assignments' 'build_assignments' 'binary_packages' 'build_assignment' \
+ 'package_sources' 'package_sources' 'build_assignments' 'package_source' \
+ 'upstream_repositories' 'upstream_repositories' 'package_sources' 'upstream_package_repository' \
+ 'repositories' 'repositories' 'binary_packages' 'repository'
+ printf ' WHERE `repositories`.`name`="build-list"'
+ printf ' AND NOT EXISTS ('
+ printf ' SELECT *'
printf ' FROM `build_slaves`'
- printf ' JOIN `build_assignments`'
- printf ' ON `build_slaves`.`currently_building`=`build_assignments`.`id`'
- printf ' WHERE `build_slaves`.`name`=from_base64("%s")' \
- "$(printf '%s' "${slave}" | base64 -w0)"
- printf '),('
- printf 'SELECT `to_dos`.`id` FROM'
- printf '('
- printf 'SELECT'
- printf ' `build_assignments`.`id`,'
- printf '('
- printf 'SELECT COUNT(*)'
- printf ' FROM `failed_builds`'
- printf ' WHERE `failed_builds`.`build_assignment`=`build_assignments`.`id`'
- printf ') AS `trials`'
- printf ' FROM `build_assignments`'
- printf ' JOIN `binary_packages`'
- printf ' ON `binary_packages`.`build_assignment`=`build_assignments`.`id`'
- printf ' JOIN `repositories`'
- printf ' ON `binary_packages`.`repository`=`repositories`.`id`'
- printf ' WHERE `repositories`.`name`="build-list"'
- printf ' AND NOT EXISTS ('
- printf ' SELECT *'
- printf ' FROM `build_slaves`'
- printf ' WHERE `build_slaves`.`currently_building`=`build_assignments`.`id`'
- printf ' )'
- printf ' ORDER BY `trials`, `build_assignments`.`id`'
- printf ' LIMIT 1'
- printf ') AS `to_dos`'
- printf ')'
- printf ')'
-} | \
- ${mysql_command} --batch --raw | \
- sed '
- 1d
- y/\t/ /
- ' >&2
+ printf ' WHERE `build_slaves`.`currently_building`=`build_assignments`.`id`'
+ printf ' AND `build_assignments`.`is_blocked` IS NULL'
+# TODO: and is element of loop or not exists unbuilt dependency
+ printf ' )'
+ printf ' ORDER BY `trials`, `build_assignments`.`id`'
+ printf ' LIMIT 1;\n'
+ } | \
+ ${mysql_command} --batch --raw | \
+ sed '
+ 1d
+ y/\t/ /
+ s/^\S\+ //
+ '
+)
+# not ready yet!
+if [ -n "${next_building}" ]; then
+ # shellcheck disable=SC2086
+ echo hand_out_assignment ${next_building} >&2
+fi
# Check if there are any pending packages at all and if the requester
# has already got an assignment.