@@ -86,7 +86,7 @@ download_ai_lite_core() {
8686}
8787
8888install_devicefarm_cli () {
89- local cli_version=" ${1:- beta-1.0.8 } "
89+ local cli_version=" ${1:- beta-1.0.9 } "
9090 local cli_out=" /tmp/devicefarm-cli-v${cli_version} .zip"
9191 local cli_dir=" /tmp/devicefarm_cli"
9292
@@ -100,93 +100,59 @@ install_devicefarm_cli() {
100100 chmod +x " ${cli_dir} /devicefarm-cli"
101101}
102102
103- reserve_if_needed () {
104- # Set default value
103+ Enqueue_device_request () {
105104 export DEVICE_RESERVED=0
106-
107105 if ! command -v devicefarm-cli > /dev/null 2>&1 ; then
108106 echo " [WARN] devicefarm-cli is not installed." >&2
109107 return 1
110108 fi
111109
112- local raw_info info_lines
113- raw_info=" $( devicefarm-cli -I) "
114-
115- info_lines=" $( printf ' %s\n' " $raw_info " | grep -v ' ^\\[INFO\\]' ) "
116-
117- local found_count
118-
119- found_count=$( printf ' %s\n' " $info_lines " \
120- | grep -Eo ' Found available reservations *: *[0-9]+' \
121- | grep -Eo ' [0-9]+' )
122- [[ -z " $found_count " ]] && found_count=0
123-
124- echo " [INFO] Current Reserved Count: $found_count "
125-
126- local THRESHOLD_SECONDS=12600
127- local any_below_threshold=0
128-
129- if (( found_count > 0 )) ; then
130- local table_body
131- table_body=$( printf ' %s\n' " $info_lines " | sed -n ' 2,$p' )
132-
133- while IFS= read -r line; do
134- if [[ " $line " =~ ^[0-9]+[[:space:]]+ ([0-9]{1,2}:[0-9]{2}:[0-9]{2}) ]]; then
135- local time_str=" ${BASH_REMATCH[1]} "
136- IFS=: read -r hh mm ss <<< " $time_str"
137- (( seconds = 10 #$hh * 3600 + 10 #$mm * 60 + 10 #$ss ))
138- if (( seconds <= THRESHOLD_SECONDS )) ; then
139- any_below_threshold=1
140- break
141- fi
142- fi
143- done <<< " $table_body"
144- else
145- any_below_threshold=1
146- fi
147-
148- if (( any_below_threshold )) ; then
149- echo " [INFO] Reserving now."
150- if ! devicefarm-cli -R; then
151- echo " ::warning::Failed to reserve a device. No devices are currently available." >&2
152- echo " [WARN] Device reservation failed - continuing without device." >&2
153- return 0
154- fi
155- else
156- echo " [INFO] Don't need to be reserved."
110+ echo " [INFO] Enqueue request (-Q)..."
111+ # Enqueue device request
112+ if ! devicefarm-cli -Q; then
113+ echo " ::warning::Failed to enqueue device request (-Q)." >&2
114+ echo " [WARN] Device queue registration failed - continuing without device." >&2
115+ return 0
157116 fi
158117
159- local info_after reservation_id max_seconds=0 max_id
118+ local interval_sec=60
119+ local out status
160120
161- info_after= " $( devicefarm-cli -I ) "
121+ echo " [INFO] Polling assignment status (-C) every ${interval_sec} s... "
162122
163- local body_after
164- body_after= $( printf ' %s\n ' " $info_after " | grep -v ' ^\\[INFO\\] ' | sed -n ' 2,$p ' )
123+ while true ; do
124+ out= " $( devicefarm-cli -C 2>&1 ) "
165125
166- while IFS= read -r line; do
167- if [[ " $line " =~ ^[0-9]+[[:space:]]+ ([0-9]{1,2}:[0-9]{2}:[0-9]{2})[[:space:]].* ([0-9a-f-]{36})$ ]]; then
168- local time_str=" ${BASH_REMATCH[1]} "
169- local id=" ${BASH_REMATCH[2]} "
170- IFS=: read -r hh mm ss <<< " $time_str"
171- (( seconds = 10 #$hh * 3600 + 10 #$mm * 60 + 10 #$ss ))
172- if (( seconds > max_seconds )) ; then
173- max_seconds=$seconds
174- max_id=$id
175- fi
126+ # Determine status: assigned / waiting / unavailable
127+ if printf ' %s' " $out " | grep -qiE ' waiting|not[[:space:]-]*assigned' ; then
128+ status=" waiting"
129+ elif printf ' %s' " $out " | grep -qi ' assigned' ; then
130+ status=" assigned"
131+ else
132+ status=" unknown"
176133 fi
177- done <<< " $body_after"
178-
179- reservation_id=$max_id
180134
181- if [[ -n " $reservation_id " ]]; then
182- devicefarm-cli -C " $reservation_id "
183- devicefarm-cli -E " ls /"
184- export DEVICE_RESERVED=1
185- echo " [INFO] Device successfully reserved and connected."
186- else
187- echo " ::warning::No available devices found." >&2
188- echo " [WARN] There is no available devices."
189- fi
135+ case " $status " in
136+ assigned)
137+ echo " [INFO] Device assigned."
138+ echo " $out "
139+ # Execute test command
140+ devicefarm-cli -E " ls /" || true
141+ export DEVICE_RESERVED=1
142+ echo " [INFO] Device successfully assigned and connected."
143+ return 0
144+ ;;
145+ waiting)
146+ echo " [INFO] Status: $status "
147+ sleep " $interval_sec "
148+ ;;
149+ * )
150+ echo " [WARN] Unknown status from -C. Output:"
151+ echo " $out "
152+ return 0
153+ ;;
154+ esac
155+ done
190156}
191157
192158install_enn_backend () {
@@ -208,9 +174,9 @@ install_enn_backend() {
208174}
209175
210176litecore_ver=" 1.0"
211- devicefarm_ver=" beta-1.0.8 "
177+ devicefarm_ver=" beta-1.0.9 "
212178
213179download_ai_lite_core ${litecore_ver}
214180install_devicefarm_cli " ${devicefarm_ver} "
215181install_enn_backend
216- reserve_if_needed
182+ Enqueue_device_request
0 commit comments