Bug 1258970 - [RFE] Python: Provide a simpler way how to find out whether a build was successful
Summary: [RFE] Python: Provide a simpler way how to find out whether a build was succe...
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: Copr
Classification: Community
Component: frontend
Version: unspecified
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Jakub Kadlčík
QA Contact:
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2015-09-01 15:46 UTC by Radek Holy
Modified: 2019-03-12 16:07 UTC (History)
3 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2019-03-12 16:07:06 UTC
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Github rholy dnf-stack-ci issues 89 0 None None None Never

Description Radek Holy 2015-09-01 15:46:54 UTC
(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 17:48:02 UTC
Valentin, please make sure this will be in APIv2.

Comment 2 Radek Holy 2015-09-02 07:05:40 UTC
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 11:04:45 UTC
>>> 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.

Comment 6 Jakub Kadlčík 2018-12-03 22:11:29 UTC
We apologize, that this took years, but it is finally implemented. Meanwhile, both APIv1 (aka Legacy API) and APIv2 (aka REST-like API) are deprecated, so this was implemented in new APIv3. See this example code

    from copr.v3 import Client
    client = Client.create_from_config_file()

    build1 = client.build_proxy.create_from_file(...)
    build2 = client.build_proxy.create_from_scm(...)
    finished = wait([build1, build2])
    print("Builds have finished {}sucessfully".format(
        "" if succeeded(finished) else "un"))

Comment 7 Jakub Kadlčík 2019-03-12 16:07:06 UTC
This BZ was fixed during the latest Copr release.
Feel free to reopen, if you encounter any difficulties with the provided solution.


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