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...");

// Keep checking until build reaches terminal state
while (!["Completed", "Cancelled", "Stopped"].includes(buildStatus)) {
try {
const response: BuildAPIResponse = await signaloidClient.get(`/builds/${buildIDFromResponse}`);
buildStatus = response.data.Status;
console.log(`...build status: ${buildStatus}`);

if (!["Completed", "Cancelled", "Stopped"].includes(buildStatus)) {
// Calculate delay with exponential backoff
retryDelayBuild = Math.min(Math.pow(2, retryCountBuild) * 1000, maxRetryDelayBuild);
console.log(`Build still active. Waiting ${retryDelayBuild}ms before retry...`);

// Wait before next check
await new Promise(resolve => setTimeout(resolve, retryDelayBuild));
retryCountBuild++;
}
} catch (error) {
console.error("Error checking build status:", error);
throw error;
}
}
// build is in a terminal state
console.log(`Build in terminal state : ${buildStatus}. Can fetch build outputs.`);
await getBuildOutputs(buildIDFromResponse); // `getBuildOutputs` is defined below.

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.