Skip to content

Commit

Permalink
backend: add a timeout for waiting until a Pulp task finishes
Browse files Browse the repository at this point in the history
  • Loading branch information
FrostyX committed Sep 10, 2024
1 parent d9d0408 commit 9eb9c43
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
5 changes: 4 additions & 1 deletion backend/copr_backend/pulp.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,18 +190,21 @@ def delete_distribution(self, distribution):
url = self.config["base_url"] + distribution
return requests.delete(url, **self.request_params)

def wait_for_finished_task(self, task):
def wait_for_finished_task(self, task, timeout=86400):
"""
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.
"""
start = time.time()
while True:
response = self.get_task(task)
if not response.ok:
break
if response.json()["state"] not in ["waiting", "running"]:
break
if time.time() > start + timeout:
break
time.sleep(5)
return response

Expand Down
13 changes: 11 additions & 2 deletions backend/copr_backend/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from copr_common.enums import StorageEnum
from copr_backend.helpers import call_copr_repo, build_chroot_log_name
from copr_backend.pulp import PulpClient
from copr_backend.exceptions import CoprBackendError


def storage_for_job(job, opts, log):
Expand Down Expand Up @@ -231,7 +232,10 @@ def upload_build_results(self, chroot, results_dir, target_dir_name):
# creating the `pulp.json` file
task = response.json()["task"]
response = self.client.wait_for_finished_task(task)
created = response.json()["created_resources"]
created = response.json().get("created_resources")
if not created:
raise CoprBackendError(
"Pulp task {0} didn't create any resources".format(task))
resources.extend(created)

self.log.info("Uploaded to Pulp: %s", path)
Expand All @@ -257,7 +261,12 @@ def publish_repository(self, chroot, **kwargs):
task, response.text)
return False

publication = response.json()["created_resources"][0]
resources = response.json()["created_resources"]
if not resources:
raise CoprBackendError(
"Pulp task {0} didn't create any resources".format(task))

publication = resources[0]
distribution_name = self._distribution_name(chroot)
distribution = self._get_distribution(chroot)

Expand Down

0 comments on commit 9eb9c43

Please sign in to comment.