1717
1818source lib/owner.sh
1919
20+ run_owner_updates () {
21+ local owners_queue
22+ local status=0
23+ owners_queue=$( get_BKG_set BKG_OWNERS_QUEUE)
24+ [ -n " $owners_queue " ] || return 0
25+
26+ if [[ " $GITHUB_OWNER " = " ipitio" && " $( git branch --show-current) " = " master" ]]; then
27+ printf ' %s\n' " $owners_queue " | parallel_shell_func " $BKG_ROOT /src/lib/owner.sh" update_owner --lb --halt soon,fail=1
28+ status=$?
29+ else # typically fewer owners
30+ run_parallel update_owner " $owners_queue "
31+ status=$?
32+ fi
33+
34+ return " $status "
35+ }
36+
2037main () {
2138 local rotated=false
2239 local owners
@@ -28,6 +45,7 @@ main() {
2845 local db_size_prev
2946 local connections
3047 local return_code=0
48+ local phase_status=0
3149 local opted_out
3250 local opted_out_before
3351 local rest_first
@@ -126,25 +144,48 @@ main() {
126144 else
127145 if [ " $GITHUB_OWNER " = " ipitio" ]; then
128146 explore " $GITHUB_OWNER " > " $connections "
147+ phase_status=$?
148+ (( phase_status != 3 )) || return_code=3
129149 explore " $GITHUB_OWNER /$GITHUB_REPO " >> " $connections "
150+ phase_status=$?
151+ (( phase_status != 3 )) || return_code=3
130152
131- # get orgs of connections
132- while read -r connection; do curl_orgs " $connection " >> " $temp_connections " ; done < " $connections "
133- cat " $temp_connections " >> " $connections "
153+ if (( return_code != 3 )) ; then
154+
155+ # get orgs of connections
156+ while read -r connection; do
157+ curl_orgs " $connection " >> " $temp_connections "
158+ phase_status=$?
159+ if (( phase_status == 3 )) ; then
160+ return_code=3
161+ break
162+ fi
163+ done < " $connections "
164+ cat " $temp_connections " >> " $connections "
165+ fi
134166
135167 sed -i ' s/^[[:space:]]*//;s/[[:space:]]*$//; /^$/d; /^0\/$/d' " $connections "
136168 # shellcheck disable=SC2319
137169 BKG_PAGE_ALL=$(
138170 (( $(wc - l < "$BKG_OWNERS ") < $(($(sort - u "$connections " | wc - l) + 100 )) ) )
139171 echo " $? "
140172 )
141- seq 1 2 | parallel_shell_func " $BKG_ROOT /src/lib/owner.sh" page_owner --lb --halt soon,fail=1
173+ if (( return_code != 3 )) ; then
174+ seq 1 2 | parallel_shell_func " $BKG_ROOT /src/lib/owner.sh" page_owner --lb --halt soon,fail=1
175+ phase_status=$?
176+ (( phase_status != 3 )) || return_code=3
177+ fi
142178 else
143179 get_membership " $GITHUB_OWNER " > " $connections "
180+ phase_status=$?
181+ (( phase_status != 3 )) || return_code=3
144182 [ " $BKG_IS_FIRST " = " false" ] || : > " $BKG_OWNERS "
145183 [ " $BKG_IS_FIRST " = " false" ] || : > " $BKG_OPTOUT "
146184 fi
147185
186+ if (( return_code == 3 )) ; then
187+ echo " Reached BKG_MAX_LEN, stopping after persisting state..."
188+ else
148189 if (( 9999 < pkg_done )) || (( pkg_left < 4 )) || [[ " ${db_size_curr::- 4} " == " ${db_size_prev::- 4} " ]]; then
149190 BKG_BATCH_FIRST_STARTED=$today
150191 set_BKG BKG_BATCH_FIRST_STARTED " $today "
@@ -168,6 +209,7 @@ main() {
168209 rm -f all_owners_in_db all_owners_tu owners_updated owners_partially_updated owners_stale
169210 set_BKG BKG_DIFF " $db_size_curr "
170211 set_BKG BKG_REST_TO_TOP " $(( 1 - rest_first)) "
212+ fi
171213 fi
172214 else
173215 save_owner " $GITHUB_OWNER "
@@ -182,10 +224,13 @@ main() {
182224 BKG_BATCH_FIRST_STARTED=$( get_BKG BKG_BATCH_FIRST_STARTED)
183225 [ -d " $BKG_INDEX_DIR " ] || mkdir " $BKG_INDEX_DIR "
184226
185- if [[ " $GITHUB_OWNER " = " ipitio" && " $( git branch --show-current) " = " master" ]]; then
186- get_BKG_set BKG_OWNERS_QUEUE | parallel_shell_func " $BKG_ROOT /src/lib/owner.sh" update_owner --lb
187- else # typically fewer owners
188- run_parallel update_owner " $( get_BKG_set BKG_OWNERS_QUEUE) "
227+ if (( return_code != 3 )) ; then
228+ run_owner_updates
229+ phase_status=$?
230+ if (( phase_status == 3 )) ; then
231+ return_code=3
232+ echo " Reached BKG_MAX_LEN, stopping after persisting state..."
233+ fi
189234 fi
190235
191236 set_BKG BKG_OUT " $( wc -l < " $BKG_OPTOUT " ) "
0 commit comments