Bug 1258970 - [RFE] Python: Provide a simpler way how to find out whether a build was successful
[RFE] Python: Provide a simpler way how to find out whether a build was succe...
Status: NEW
Product: Copr
Classification: Community
Component: frontend (Show other bugs)
unspecified
Unspecified Unspecified
unspecified Severity unspecified
: ---
: ---
Assigned To: Miroslav Suchý
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2015-09-01 11:46 EDT by Radek Holy
Modified: 2015-12-01 01:34 EST (History)
2 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed:
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Radek Holy 2015-09-01 11:46:54 EDT
(I miss a component for python-copr)

Please, provide a simpler way how to find out whether a build was successful.

Currently, I do:
    result = cl.create_new_build(project, pkgs=pkgs)
    success = all(build.handle.get_build_details().status != 'failed' for build in result.builds_list)

BTW, is this correct? I mean, do I use API?

I think that this is unnecessarily chatty since it is probably were common task. I am thinking about something like "result.success()".
Comment 1 Miroslav Suchý 2015-09-01 13:48:02 EDT
Valentin, please make sure this will be in APIv2.
Comment 2 Radek Holy 2015-09-02 03:05:40 EDT
s/were/very

BTW, I forgot to add the loop waiting for the build to be finished:

    result = cl.create_new_build(project, pkgs=pkgs)
    while True:
        remaining = [bw.build_id for bw in result.builds_list if bw.handle.get_build_details().status not in ["skipped", "failed", "succeeded"]]
        if not remaining:
            break
        time.sleep(1)
    success = all(build.handle.get_build_details().status != 'failed' for build in result.builds_list)

The loop is also going to repeat in a lot of the COPR clients, I guess. Maybe the new function can be similar to Python's "Popen.wait(timeout=None)". It could wait for the build to terminate and return the status. Or something like the "Popen.poll()" (this is the original request). Or even we could have something like "Popen.call()" in addition to "cl.create_new_build".

What do you think about these proposals? Which variant are you going to choose? I can file an RFE for each of these proposals since all of them makes sense to me and I can imagine that they can live together.
Comment 3 Valentin Gologuzov 2015-09-03 07:04:45 EDT
>>> I think that this is unnecessarily chatty since it is probably were common task. 

Well it is, but we now talking about business logic, and API should only provide an interface to the service. If we implement this task some user may want to show progress, so we would be forced to add some hook function.


>>> I am thinking about something like "result.success()"
Seems reasonable, accepted.

>>> The loop is also going to repeat in a lot of the COPR clients, I guess. Maybe the new function can be similar to Python's "Popen.wait(timeout=None)". It could wait for the build to terminate and return the status. Or something like the "Popen.poll()" (this is the original request). Or even we could have something like "Popen.call()" in addition to "cl.create_new_build".

Well, python-copr uses HTTP requests to communicate with the Copr service, so any .wait() method would be translated into the periodical calls to the service.
I would think about addition of a helper function 
`wait_builds(build_id_list, check_period=60)` which would block until all given builds are finished.

Note You need to log in before you can comment on or make changes to this bug.