Skip to main content

Querying Build Status and Output

Fetching build status from the API

Once a build, either a single-file source one or one from a GitHub repository, has been accepted, you can use its BuildID to query the status of the build from the API by making a GET request to /builds/{buildID}. The Signaloid Cloud Compute Engine returns the Build status in the Status field of the response object. You should continue to poll the API until the build status is in a terminal state; i.e., either Completed, Cancelled, or Stopped.

The code snippet below shows how to fetch the status of the task from the API using the axios library.

interface BuildAPIResponse {
data: {
Status: string;
// Add other properties here
};
}

let buildIDFromResponse = buildPostResponse.data.BuildID;
let buildStatus = "";
let retryCountBuild = 0;
let retryDelayBuild = 2000;
let buildLog: string;
const maxRetryDelayBuild = 30000;

console.log("Waiting for the build to finish...");
await getBuildStatus(buildIDFromResponse);

// Helper functions for fetching build status with backoff
async function getBuildStatus(buildID: string) {
try {
// get build data from API
const response = await signaloidClient.get(`/builds/${buildIDFromResponse}`);
buildAPIResponseHandler(response);
} catch (error) {
console.log("Error:", error);
}
}

async function buildAPIResponseHandler(response: BuildAPIResponse) {
if ("Status" in response.data) {
buildStatus = response.data.Status;
console.log(`...build status : ${buildStatus}`);
} else {
throw new Error("Build status not found in response");
}

if (["Completed", "Cancelled", "Stopped"].includes(buildStatus)) {
// task is in a terminal state
console.log(`Build in terminal state : ${buildStatus}. Can fetch task outputs.`);
await getBuildOutputs(buildIDFromResponse); // `getBuildOutputs` is defined below.
} else {
// build is not in a terminal state. retry with delay
retryCountBuild += 1;
retryDelayBuild = Math.min(Math.pow(2, retryCountBuild) * 1000, maxRetryDelayBuild);
console.log(`Build still active : ${buildStatus}. Waiting for ${retryDelayBuild}ms and retying...`);
setTimeout(() => {
getBuildStatus(buildIDFromResponse);
}, retryDelayBuild);
}
}

Retrieving build outputs from the API

Once the build is in a terminal state, you can retrieve the outputs of the build from the API by making a GET request to /builds/{buildsID}/outputs. The output is the standard error output of the compilation process of the single file source code or GitHub repository that you chose.

The code snippet below shows an implementation of the getBuildOutputs placeholder function referred to in the previous step that will fetch the outputs of the build from the API using the axios library.

// Helper function for fetching task output
async function getBuildOutputs(buildID: string) {
console.log("Fetching build outputs...");
try {
// get build data from API
const buildOutputsResponse = await signaloidClient.get(`/builds/${buildID}/outputs`);
if (buildOutputsResponse.data.Build) {
const outputStream = await axios.get(buildOutputsResponse.data.Build);
buildLog = outputStream.data;
console.log(`Build Log: \n${buildLog}`);
}
} catch (error) {
console.log("Error:", error);
}
}

The build outputs response will have the following shape:

{
"data": {
"Build": "...",
},
"status": 200,
"statusText": "Ok"
}

The Build key of the data key in this object is a URL to the file containing the build standard error output of the application. The stream may be empty for a build with no warnings or errors.