It's all about the answers!

Ask a question

[Solved] How to find how long a build has been queued - java api. (or how to get IBuildRequest from IBuildResult)


M Holder (53610) | asked Mar 19 '15, 2:57 p.m.
edited Mar 20 '15, 1:37 p.m.
Using the java api - how do I find out how long a build has been queued?
I've got the IBuildResult but don't know how to get the corresponding IBuildRequest

I've 2 use-cases:
1) When a build starts I wish to log (in a DB) how long it has been waiting so we've a record of how bad our queue times are, and a record of total time from request to completed build.
2) I want to see how long builds are queuing for each build definition. This is so I can warn if builds have been queued for too long for a certain definition. I can then also add build engines to supports the definitions with the longest queues.

In both cases we've got the IBuildResult already.
In (1) we use the IBuildResult already to tag the build and for use case 2, I use an IItemQuery to find build results for definition X in BuildState.NOT_STARTED

I've tried IBuildResult.getBuildRequests() but that only returns an empty List.

Presumably if I could get to an IBuildRequest I could use IBuildRequest.getCreated() to find when it was queued?

One answer



permanent link
M Holder (53610) | answered Mar 20 '15, 1:34 p.m.
It turns out that  was on the right track using IBuildResult.getBuildRequests() which was returning an empty list of IBuildRequestHandles.

My problem was I'd not actually got the full IBuildResult, I'd only got a partial IBuildResult.
Mainly PEBKAC but I was thrown by the lack of documentation (I must accept there is no javadoc and just get the source), and but the List of requests - I don't understand how a build would have multiple requests.

The following seems to do very roughly what I was wanting (null checks etc omitted for brevity)
    public void processBuildQueue(ITeamBuildClient buildClient) throws TeamRepositoryException {
        IItemQuery query = IItemQuery.FACTORY.newInstance(IBuildResultQueryModel.ROOT);

query.filter(IBuildResultQueryModel.ROOT.buildState()._eq(BuildState.NOT_STARTED.name()));
IItemQueryPage page = buildClient.queryItems(query, new String[0], IQueryService.ITEM_QUERY_MAX_PAGE_SIZE, null);

List<IBuildResult> builds = repo.itemManager().fetchPartialItems(page.getItemHandles(),
IItemManager.DEFAULT,
Arrays.asList(IBuildResult.PROPERTY_BUILD_REQUESTS,
IBuildResult.PROPERTY_BUILD_DEFINITION),
null);

for (IBuildResult result : builds) {
IBuildDefinition buildDefinition = (IBuildDefinition) repo.itemManager().fetchCompleteItem(result.getBuildDefinition(), IItemManager.DEFAULT, null);
System.out.print(buildDefinition.getId());
List<IBuildRequestHandle> requests = result.getBuildRequests();
for (IBuildRequestHandle requestHandle : requests) { //Why would there be multiple requests?
IBuildRequest buildRequest = (IBuildRequest) repo.itemManager().fetchCompleteItem(requestHandle, IItemManager.DEFAULT, null);
Timestamp ts = buildRequest.getCreated();
System.out.println(" requested:" + ts + " queue time:" + secondsSince(ts) + " seconds.");
}
}
}

Your answer


Register or to post your answer.


Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.