Skip to content

Commit

Permalink
Improved build request management, enabling user to cancel and indica…
Browse files Browse the repository at this point in the history
…ting whether processing has commenced.
  • Loading branch information
blckmn committed Jan 7, 2024
1 parent 842194f commit 1d42316
Show file tree
Hide file tree
Showing 16 changed files with 84 additions and 52 deletions.
4 changes: 2 additions & 2 deletions locales/ca/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -3335,10 +3335,10 @@
"firmwareFlasherCloudBuildSuccess": {
"message": "èxit"
},
"firmwareFlasherCloudBuildTimedOut": {
"firmwareFlasherCloudBuildFailTimeOut": {
"message": "s'ha esgotat el temps d'espera (torneu-ho a provar)"
},
"firmwareFlasherCloudBuildFailed": {
"firmwareFlasherCloudBuildFail": {
"message": "ha fallat (comproveu el registre)"
},
"firmwareFlasherReleaseFileUrl": {
Expand Down
4 changes: 2 additions & 2 deletions locales/da/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -3331,10 +3331,10 @@
"firmwareFlasherCloudBuildSuccess": {
"message": "succes"
},
"firmwareFlasherCloudBuildTimedOut": {
"firmwareFlasherCloudBuildFailTimeOut": {
"message": "timeout (prøv igen)"
},
"firmwareFlasherCloudBuildFailed": {
"firmwareFlasherCloudBuildFail": {
"message": "mislykkedes (tjek log)"
},
"firmwareFlasherReleaseFileUrl": {
Expand Down
4 changes: 2 additions & 2 deletions locales/de/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -2970,10 +2970,10 @@
"firmwareFlasherCloudBuildSuccess": {
"message": "Erfolgreich"
},
"firmwareFlasherCloudBuildTimedOut": {
"firmwareFlasherCloudBuildFailTimeOut": {
"message": "Zeitüberschreitung (bitte erneut versuchen)"
},
"firmwareFlasherCloudBuildFailed": {
"firmwareFlasherCloudBuildFail": {
"message": "Fehlgeschlagen (bitte Log prüfen)"
},
"firmwareFlasherReleaseFileUrl": {
Expand Down
9 changes: 6 additions & 3 deletions locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1397,7 +1397,7 @@
},
"configurationMotorIdleRpmHelp" : {
"message": "This is the dynamic idle value from the active PID profile. When Dynamic Idle is set to zero, only static motor idle will apply. Change the Dynamic Idle settings on the PID tuning tab.",
"description": "Help text for dynamic idle setting"
"description": "Help text for dynamic idle setting"
},
"configurationThrottleMinimum": {
"message": "Minimum Throttle (Lowest ESC value when armed)"
Expand Down Expand Up @@ -3415,10 +3415,13 @@
"firmwareFlasherCloudBuildSuccess": {
"message": "success"
},
"firmwareFlasherCloudBuildTimedOut": {
"firmwareFlasherCloudBuildFailCancel": {
"message": "cancelled"
},
"firmwareFlasherCloudBuildFailTimeOut": {
"message": "timed out (please retry)"
},
"firmwareFlasherCloudBuildFailed": {
"firmwareFlasherCloudBuildFail": {
"message": "failed (please check log)"
},
"firmwareFlasherReleaseFileUrl": {
Expand Down
4 changes: 2 additions & 2 deletions locales/es/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -3327,10 +3327,10 @@
"firmwareFlasherCloudBuildSuccess": {
"message": "éxito"
},
"firmwareFlasherCloudBuildTimedOut": {
"firmwareFlasherCloudBuildFailTimeOut": {
"message": "tiempo agotado (vuelve a intentarlo)"
},
"firmwareFlasherCloudBuildFailed": {
"firmwareFlasherCloudBuildFail": {
"message": "error (revisa el registro)"
},
"firmwareFlasherReleaseFileUrl": {
Expand Down
4 changes: 2 additions & 2 deletions locales/fr/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -2894,10 +2894,10 @@
"firmwareFlasherCloudBuildSuccess": {
"message": "succès"
},
"firmwareFlasherCloudBuildTimedOut": {
"firmwareFlasherCloudBuildFailTimeOut": {
"message": "temps expiré (veuillez réessayer)"
},
"firmwareFlasherCloudBuildFailed": {
"firmwareFlasherCloudBuildFail": {
"message": "échec (veuillez vérifier le log)"
},
"firmwareFlasherReleaseFileUrl": {
Expand Down
4 changes: 2 additions & 2 deletions locales/gl/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -3330,10 +3330,10 @@
"firmwareFlasherCloudBuildSuccess": {
"message": "éxito"
},
"firmwareFlasherCloudBuildTimedOut": {
"firmwareFlasherCloudBuildFailTimeOut": {
"message": "tempo esgotado (volva a intentalo)"
},
"firmwareFlasherCloudBuildFailed": {
"firmwareFlasherCloudBuildFail": {
"message": "fallou (verifique o rexistro)"
},
"firmwareFlasherReleaseFileUrl": {
Expand Down
4 changes: 2 additions & 2 deletions locales/it/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -3327,10 +3327,10 @@
"firmwareFlasherCloudBuildSuccess": {
"message": "successo"
},
"firmwareFlasherCloudBuildTimedOut": {
"firmwareFlasherCloudBuildFailTimeOut": {
"message": "timeout (riprova)"
},
"firmwareFlasherCloudBuildFailed": {
"firmwareFlasherCloudBuildFail": {
"message": "fallito (si prega di controllare il log)"
},
"firmwareFlasherReleaseFileUrl": {
Expand Down
4 changes: 2 additions & 2 deletions locales/ja/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -3327,10 +3327,10 @@
"firmwareFlasherCloudBuildSuccess": {
"message": "成功しました"
},
"firmwareFlasherCloudBuildTimedOut": {
"firmwareFlasherCloudBuildFailTimeOut": {
"message": "タイムアウトしました (再試行してください)"
},
"firmwareFlasherCloudBuildFailed": {
"firmwareFlasherCloudBuildFail": {
"message": "失敗しました (ログを確認してください)"
},
"firmwareFlasherReleaseFileUrl": {
Expand Down
4 changes: 2 additions & 2 deletions locales/ko/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -3331,10 +3331,10 @@
"firmwareFlasherCloudBuildSuccess": {
"message": "성공"
},
"firmwareFlasherCloudBuildTimedOut": {
"firmwareFlasherCloudBuildFailTimeOut": {
"message": "시간 초과됨 (재시도하세요)"
},
"firmwareFlasherCloudBuildFailed": {
"firmwareFlasherCloudBuildFail": {
"message": "실패 (로그기록을 확인하세요)"
},
"firmwareFlasherReleaseFileUrl": {
Expand Down
4 changes: 2 additions & 2 deletions locales/pl/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -3331,10 +3331,10 @@
"firmwareFlasherCloudBuildSuccess": {
"message": "ukończono"
},
"firmwareFlasherCloudBuildTimedOut": {
"firmwareFlasherCloudBuildFailTimeOut": {
"message": "przekroczono limit czasu (spróbuj ponownie)"
},
"firmwareFlasherCloudBuildFailed": {
"firmwareFlasherCloudBuildFail": {
"message": "nie powiodło się (proszę sprawdzić logi)"
},
"firmwareFlasherReleaseFileUrl": {
Expand Down
4 changes: 2 additions & 2 deletions locales/pt/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -3327,10 +3327,10 @@
"firmwareFlasherCloudBuildSuccess": {
"message": "sucesso"
},
"firmwareFlasherCloudBuildTimedOut": {
"firmwareFlasherCloudBuildFailTimeOut": {
"message": "tempo expirou (pf tente novamente)"
},
"firmwareFlasherCloudBuildFailed": {
"firmwareFlasherCloudBuildFail": {
"message": "falhou (pf verifique o log)"
},
"firmwareFlasherReleaseFileUrl": {
Expand Down
4 changes: 2 additions & 2 deletions locales/pt_BR/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -3124,10 +3124,10 @@
"firmwareFlasherCloudBuildSuccess": {
"message": "sucesso"
},
"firmwareFlasherCloudBuildTimedOut": {
"firmwareFlasherCloudBuildFailTimeOut": {
"message": "tempo esgotado (tente novamente)"
},
"firmwareFlasherCloudBuildFailed": {
"firmwareFlasherCloudBuildFail": {
"message": "falhou (por favor, verifique o log)"
},
"firmwareFlasherReleaseFileUrl": {
Expand Down
4 changes: 2 additions & 2 deletions locales/uk/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -3327,10 +3327,10 @@
"firmwareFlasherCloudBuildSuccess": {
"message": "успішно"
},
"firmwareFlasherCloudBuildTimedOut": {
"firmwareFlasherCloudBuildFailTimeOut": {
"message": "час вийшов (спробуйте ще раз)"
},
"firmwareFlasherCloudBuildFailed": {
"firmwareFlasherCloudBuildFail": {
"message": "не вдалося (перевірте журнал)"
},
"firmwareFlasherReleaseFileUrl": {
Expand Down
72 changes: 49 additions & 23 deletions src/js/tabs/firmware_flasher.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import Sponsor from '../Sponsor';

const firmware_flasher = {
targets: null,
releaseLoader: new BuildApi(),
buildApi: new BuildApi(),
sponsor: new Sponsor(),
localFirmwareLoaded: false,
selectedBoard: undefined,
Expand All @@ -39,6 +39,7 @@ const firmware_flasher = {
configFilename: null,
config: {},
developmentFirmwareLoaded: false, // Is the firmware to be flashed from the development branch?
cancelBuild: false,
};

firmware_flasher.initialize = function (callback) {
Expand Down Expand Up @@ -325,7 +326,7 @@ firmware_flasher.initialize = function (callback) {

if (!GUI.connect_lock) {
try {
self.releaseLoader.loadTargets(loadTargetList);
self.buildApi.loadTargets(loadTargetList);
} catch (err) {
console.error(err);
}
Expand Down Expand Up @@ -360,7 +361,7 @@ firmware_flasher.initialize = function (callback) {
const expertMode = expertMode_e.is(':checked');
if (expertMode) {
if (response.releaseType === 'Unstable') {
self.releaseLoader.loadCommits(response.release, (commits) => {
self.buildApi.loadCommits(response.release, (commits) => {
const select_e = $('select[name="commits"]');
select_e.empty();
commits.forEach((commit) => {
Expand All @@ -384,12 +385,12 @@ firmware_flasher.initialize = function (callback) {
self.enableLoadRemoteFileButton(true);
}

self.releaseLoader.loadTarget(target, release, onTargetDetail);
self.buildApi.loadTarget(target, release, onTargetDetail);

if (self.validateBuildKey() && navigator.onLine) {
self.releaseLoader.loadOptionsByBuildKey(release, self.cloudBuildKey, buildOptions);
self.buildApi.loadOptionsByBuildKey(release, self.cloudBuildKey, buildOptions);
} else {
self.releaseLoader.loadOptions(release, buildOptions);
self.buildApi.loadOptions(release, buildOptions);
}
}

Expand Down Expand Up @@ -514,7 +515,7 @@ firmware_flasher.initialize = function (callback) {
),
);

self.releaseLoader.loadTargetReleases(target, (data) => populateReleases(versions_e, data));
self.buildApi.loadTargetReleases(target, (data) => populateReleases(versions_e, data));
}
}
});
Expand Down Expand Up @@ -761,6 +762,11 @@ firmware_flasher.initialize = function (callback) {
},
);

$('a.cloud_build_cancel').on('click', function (evt) {
$('a.cloud_build_cancel').toggleClass('disabled', true);
self.cancelBuild = true;
});

$('a.load_remote_file').on('click', function (evt) {
if (!self.selectedBoard) {
return;
Expand Down Expand Up @@ -791,15 +797,15 @@ firmware_flasher.initialize = function (callback) {
$('.buildProgress').val(val);
}

function processBuildStatus(response, statusResponse, retries) {
function processBuildStatus(response, statusResponse, suffix) {
if (statusResponse.status === 'success') {
updateStatus(retries <= 0 ? 'SuccessCached' : "Success", response.key, 100, true);
updateStatus(`Success${suffix}`, response.key, 100, true);
if (statusResponse.configuration !== undefined && !self.isConfigLocal) {
setBoardConfig(statusResponse.configuration);
}
self.releaseLoader.loadTargetHex(response.url, (hex) => onLoadSuccess(hex, response.file), onLoadFailed);
self.buildApi.loadTargetHex(response.url, (hex) => onLoadSuccess(hex, response.file), onLoadFailed);
} else {
updateStatus(retries > 10 ? 'TimedOut' : "Failed", response.key, 0, true);
updateStatus(`Fail${suffix}`, response.key, 0, true);
onLoadFailed();
}
}
Expand Down Expand Up @@ -844,40 +850,60 @@ firmware_flasher.initialize = function (callback) {
}

console.info("Build request:", request);
self.releaseLoader.requestBuild(request, (response) => {
self.buildApi.requestBuild(request, (response) => {
console.info("Build response:", response);

// Complete the summary object to be used later
self.targetDetail.file = response.file;

if (!targetDetail.cloudBuild) {
// it is a previous release, so simply load the hex
self.releaseLoader.loadTargetHex(response.url, (hex) => onLoadSuccess(hex, response.file), onLoadFailed);
self.buildApi.loadTargetHex(response.url, (hex) => onLoadSuccess(hex, response.file), onLoadFailed);
return;
}

updateStatus('Pending', response.key, 0, false);
self.cancelBuild = false;

let retries = 1;
self.releaseLoader.requestBuildStatus(response.key, (statusResponse) => {
self.buildApi.requestBuildStatus(response.key, (statusResponse) => {
if (statusResponse.status !== "queued") {
// will be cached already, no need to wait.
processBuildStatus(response, statusResponse, 0);
processBuildStatus(response, statusResponse, "Cached");
return;
}

$('a.cloud_build_cancel').toggleClass('disabled', false);
const retrySeconds = 5;
const timer = setInterval(() => {
self.releaseLoader.requestBuildStatus(response.key, (statusResponse) => {
if (statusResponse.status !== 'queued' || retries > 10) {
self.buildApi.requestBuildStatus(response.key, (statusResponse) => {
const timeout = statusResponse.timeOut !== undefined ? statusResponse.timeOut : 60;
const retryTotal = timeout / retrySeconds;

if (statusResponse.status !== 'queued' || retries > retryTotal || self.cancelBuild) {
let suffix = "";
if (retries > retryTotal) {
suffix = "TimeOut";
}

if (self.cancelBuild) {
suffix = "Cancel";
}

$('a.cloud_build_cancel').toggleClass('disabled', true);
self.cancelBuild = false;
clearInterval(timer);
processBuildStatus(response, statusResponse, retries);

processBuildStatus(response, statusResponse, suffix);
return;
}

updateStatus('Processing', response.key, retries * 10, false);
retries++;
updateStatus('Processing', response.key, retries * (100 / retryTotal), false);
if (statusResponse.timeOut !== undefined) {
retries++;
}
});
}, 5000);
}, retrySeconds * 1000);
});
}, onLoadFailed);
}
Expand Down Expand Up @@ -1159,7 +1185,7 @@ firmware_flasher.initialize = function (callback) {
GUI.content_ready(callback);
}

self.releaseLoader.loadTargets(() => {
self.buildApi.loadTargets(() => {
$('#content').load("./tabs/firmware_flasher.html", onDocumentLoad);
});
};
Expand Down Expand Up @@ -1267,7 +1293,7 @@ firmware_flasher.verifyBoard = function() {
self.cloudBuildKey = FC.CONFIG.buildKey;

if (self.validateBuildKey()) {
self.releaseLoader.requestBuildOptions(self.cloudBuildKey, getCloudBuildOptions, getBoardInfo);
self.buildApi.requestBuildOptions(self.cloudBuildKey, getCloudBuildOptions, getBoardInfo);
} else {
getBoardInfo();
}
Expand Down
3 changes: 3 additions & 0 deletions src/tabs/firmware_flasher.html
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,9 @@
<progress class="buildProgress" value="0" min="0" max="100"></progress>
<span id="cloudTargetStatus"></span>
<br />
<div class="btn default_btn">
<a class="cloud_build_cancel disabled" href="#" i18n="cancel"></a>
</div>
</div>
</div>
</div>
Expand Down

0 comments on commit 1d42316

Please sign in to comment.