[Buildbot-devel] Buildbot-devel Digest, Vol 41, Issue 10

Zhu Jia Cheng realalien at gmail.com
Wed Sep 16 08:50:12 UTC 2009


Hi! All,
    I did some modification on my local Buildbot's code, but I am not
sureif my way of hacking breaks some rules or produces bad-smelling
code, or if
there is a better way there (I found it's quite hard to write a test first
or draw a UML diagram, considering my 5 month exp. in Python ). Would
someone be kind enough to take a look and give some suggestions? (
LinesOfCode < 20)

    The original idea was to stop all the pending builds except the last
building/pending one on each builder when there are lots of long-duration
builds queuing(sometimes a critical fix waits behind some "to-be-failed"
 pending ones.)

     My solution is as follows, (see Bold line),  I will be very grateful
for any suggestions.
--------------------------------------------------------------------------------
* modifying code which handles /builders/_all/stop.
in:   status.web.builder , class StatusResourceAllBuilders
<pre>
def stop(self, req):
        for bname in self.status.getBuilderNames():
            builder_status = self.status.getBuilder(bname)
            builder_control = None
            c = self.getControl(req)
            if c:
                builder_control = c.getBuilder(bname)
            (state, current_builds) = builder_status.getState()

            if state != "building" and state != "pending":
                continue
            elif state == "pending" :
                builder_control.cancelAllPendingsExceptLastOne()
            elif state == "building" :
                if len(builder_status.getPendingBuilds()) > 0:  # keep the
last pending one
                    builder_control.cancelAllPendingsExceptLastOne()
                    for b in current_builds:
                        log.msg("!!!!   current build [ %s ] number [%s] to
stop " % (str(b), str(b.number)))
                        build_status = builder_status.getBuild(b.number)

                        if not build_status:
                            continue
                        if builder_control:
                            build_control =
builder_control.getBuild(b.number)
                        else:
                            build_control = None
                        build = StatusResourceBuild(build_status,
build_control,
                                                    builder_control)
                        build.stop(req)
                else:
                    pass  # no pending, just ignore stop instruction

        # go back to the welcome page
        return Redirect("../..")
</pre>

--------------------------------------------------------------------------------
in:  process.builder , class BuilderControl
<pre>
    def cancelAllPendingsExceptLastOne(self):
        """test method, see if they are available to be called."""
        if len(self.original.buildable) > 0:
            for p in self.original.buildable[:-1]:
                self.original.builder_status.removeBuildRequest(p.status)
            self.original.buildable = self.original.buildable[-1:]
        return
</pre>
--------------------------------------------------------------------------------
in: interface, class IBuilderControl
<pre>
        def cancelAllPendingsExceptLastOne():
        """remove all pending build request"""
</pre>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://buildbot.net/pipermail/devel/attachments/20090916/34debf3e/attachment.html>


More information about the devel mailing list