fixed handling of empty responses
This commit is contained in:
parent
915e8076d6
commit
46b7b8d8b7
1 changed files with 7 additions and 5 deletions
|
@ -232,9 +232,9 @@ def rest_request_iterator(
|
||||||
"Got status code {} on request to {}".format(response.status_code, url)
|
"Got status code {} on request to {}".format(response.status_code, url)
|
||||||
)
|
)
|
||||||
results = response.json()[array_field_name]
|
results = response.json()[array_field_name]
|
||||||
yield results
|
if len(results) == 0:
|
||||||
if len(results) < step:
|
|
||||||
return
|
return
|
||||||
|
yield results
|
||||||
start_id = stop_id
|
start_id = stop_id
|
||||||
|
|
||||||
|
|
||||||
|
@ -259,8 +259,6 @@ def update_buildsets(conn: psycopg2.extensions.connection):
|
||||||
for result_set in rest_request_iterator(
|
for result_set in rest_request_iterator(
|
||||||
url, "buildsets", "bsid", start_id=start_id
|
url, "buildsets", "bsid", start_id=start_id
|
||||||
):
|
):
|
||||||
if len(result_set) == 0:
|
|
||||||
break
|
|
||||||
args_str = b",".join(
|
args_str = b",".join(
|
||||||
cur.mogrify(
|
cur.mogrify(
|
||||||
b" (%s,%s) ",
|
b" (%s,%s) ",
|
||||||
|
@ -270,6 +268,8 @@ def update_buildsets(conn: psycopg2.extensions.connection):
|
||||||
if buildset["complete"]
|
if buildset["complete"]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if len(args_str) == 0:
|
||||||
|
break
|
||||||
cur.execute(
|
cur.execute(
|
||||||
b"INSERT INTO buildbot_buildsets (buildset_id, data) values " + args_str
|
b"INSERT INTO buildbot_buildsets (buildset_id, data) values " + args_str
|
||||||
)
|
)
|
||||||
|
@ -294,7 +294,7 @@ def update_buildrequests(conn: psycopg2.extensions.connection):
|
||||||
for result_set in rest_request_iterator(
|
for result_set in rest_request_iterator(
|
||||||
url, "buildrequests", "buildrequestid", start_id=start_id
|
url, "buildrequests", "buildrequestid", start_id=start_id
|
||||||
):
|
):
|
||||||
# cur.mogrify returns byte string, so we need to join on a byte string
|
# cur.mogrify returns a byte string, so we need to join on a byte string
|
||||||
args_str = b",".join(
|
args_str = b",".join(
|
||||||
cur.mogrify(
|
cur.mogrify(
|
||||||
" (%s,%s,%s) ",
|
" (%s,%s,%s) ",
|
||||||
|
@ -307,6 +307,8 @@ def update_buildrequests(conn: psycopg2.extensions.connection):
|
||||||
for buildrequest in result_set
|
for buildrequest in result_set
|
||||||
if buildrequest["complete"]
|
if buildrequest["complete"]
|
||||||
)
|
)
|
||||||
|
if len(args_str) == 0:
|
||||||
|
break
|
||||||
cur.execute(
|
cur.execute(
|
||||||
b"INSERT INTO buildbot_buildrequests (buildrequest_id, buildset_id, data) values "
|
b"INSERT INTO buildbot_buildrequests (buildrequest_id, buildset_id, data) values "
|
||||||
+ args_str
|
+ args_str
|
||||||
|
|
Loading…
Reference in a new issue