9ffda9e5b601497b1ddcda75d5bbf377c1156713
hiram
  Mon Jun 8 14:32:29 2026 -0700
watch for a build to have completed refs #31811

diff --git src/hg/utils/otto/userRequests/asmRequestWatch.sh src/hg/utils/otto/userRequests/asmRequestWatch.sh
index e1e7161256d..f80129f6a69 100755
--- src/hg/utils/otto/userRequests/asmRequestWatch.sh
+++ src/hg/utils/otto/userRequests/asmRequestWatch.sh
@@ -131,30 +131,58 @@
         "UPDATE ottoRequest SET status=2, buildDir='${buildDir}' \
          WHERE id=${reqId};" ${centDb}
       ;;
     *)
       scriptName=$(basename "$0")
       printf "ERROR: %s: Multiple trackData directories found for %s:\n" "${scriptName}" "${accPath}" 1>&2
       printf "  %s\n" "${trackDataDirs[@]}" 1>&2
       setErrorStatus "${reqId}"
       ;;
   esac
 
 done < <(/cluster/bin/x86_64/${hgSql} -N -B -e \
   "SELECT id, fromDb FROM ottoRequest WHERE status = 1 AND buildDir = '' AND requestType = 'assembly';" \
   ${centDb})
 
+############################################################################
+# phase 2: watch for a build to have completed
+############################################################################
+while IFS=$'\t' read -r reqId fromDb; do
+  accPath=$(accessionToPath "${fromDb}")
+  # if the trackDb.txt file is present, the build is finished
+  shopt -s nullglob  # make globs expand to nothing if no matches
+  trackDbFile=(/hive/data/genomes/asmHubs/allBuild/${accPath}/${fromDb}_*/${fromDb}_*.trackDb.txt)
+  shopt -u nullglob  # restore default behavior
+  # Check the results
+  case ${#trackDbFile[@]} in
+    0)	# no trackDb.txt file seen yet, not done
+      ;;
+    1)  # single file seen - build is complete
+      /cluster/bin/x86_64/${hgSql} -N -e \
+        "UPDATE ottoRequest SET status=3 WHERE id=${reqId};" ${centDb}
+      ;;
+    *)
+      scriptName=$(basename "$0")
+      printf "ERROR: %s: Multiple trackDb.txt files found for %s:\n" "${scriptName}" "${accPath}" 1>&2
+      printf "  %s\n" "${trackDbFile[@]}" 1>&2
+      setErrorStatus "${reqId}"
+      ;;
+  esac
+
+done < <(/cluster/bin/x86_64/${hgSql} -N -B -e \
+  "SELECT id, fromDb FROM ottoRequest WHERE status = 2 AND requestType = 'assembly';" \
+  ${centDb})
 
 ############################################################################
 # check for phase 6: the assembly is complete and available on the RR
 #       this checking and setting status 6 is currently done manually,
 #       eventually this will become automatic.
 ############################################################################
 while IFS=$'\t' read -r reqId fromDb comment requestTime; do
 
   export gcX="${fromDb:0:3}"
   export d0="${fromDb:4:3}"
   export d1="${fromDb:7:3}"
   export d2="${fromDb:10:3}"
   export gbDbPath="/gbdb/genark/${gcX}/${d0}/${d1}/${d2}/${fromDb}/hub.txt"
   export hubTxt="https://genome.ucsc.edu/cgi-bin/hgTracks?genome=${fromDb}&hubUrl=${gbDbPath}"