Skip to content

Commit

Permalink
copr: wait until Pulp publication is finished
Browse files Browse the repository at this point in the history
  • Loading branch information
FrostyX committed Sep 5, 2024
1 parent e063b3b commit 200d0d1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
16 changes: 16 additions & 0 deletions backend/copr_backend/pulp.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""

import os
import time
import tomllib
from urllib.parse import urlencode
import requests
Expand Down Expand Up @@ -227,3 +228,18 @@ def get_latest_repository_version(self, name):

response = requests.get(url, **self.request_params)
return response.json()["results"][0]["pulp_href"]

def wait_for_finished_task(self, task):
"""
Pulp task (e.g. creating a publication) can be running for an
unpredictably long time. We need to wait until it is finished to know
what it actually did.
"""
while True:
response = self.get_task(task)
if not response.ok:
break
if response.json()["state"] != "waiting":
break
time.sleep(5)
return response
2 changes: 1 addition & 1 deletion backend/copr_backend/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ def publish_repository(self, chroot, **kwargs):
return False

task = response.json()["task"]
response = self.client.get_task(task)
response = self.client.wait_for_finished_task(task)
if not response.ok:
self.log.error("Failed to get Pulp task %s because of %s",
task, response.text)
Expand Down

0 comments on commit 200d0d1

Please sign in to comment.