Poll for the placement suggestion instead of waiting on it
Matching pictures to the script is a model call and cannot answer inside the few seconds the API gateway allows, so it returned "Function timed out". It now starts in the background and this waits for it, the same way frames and joins already do.
This commit is contained in:
parent
838f308ba9
commit
d175b3b926
1 changed files with 15 additions and 0 deletions
15
script.html
15
script.html
|
|
@ -366,6 +366,21 @@ function bindPics() {
|
||||||
if (!PICS.length) { showMsg("msg", "Add a picture first."); return; }
|
if (!PICS.length) { showMsg("msg", "Add a picture first."); return; }
|
||||||
sg.disabled = true; sg.textContent = "Reading the script…";
|
sg.disabled = true; sg.textContent = "Reading the script…";
|
||||||
var r = await api("suggest_image_placements", { email: email, project_id: pid });
|
var r = await api("suggest_image_placements", { email: email, project_id: pid });
|
||||||
|
if (!r.ok) { sg.disabled = false; sg.textContent = "Suggest where they fit"; showMsg("msg", r.error || "Could not suggest."); return; }
|
||||||
|
// Reading the script is a model call, far too slow to answer inside one
|
||||||
|
// request, so it runs in the background and we wait for it here.
|
||||||
|
if (r.pending) {
|
||||||
|
document.getElementById("sugnote").textContent = r.status_text || "Reading the script…";
|
||||||
|
var waited = 0;
|
||||||
|
r = await new Promise(function (done) {
|
||||||
|
var t = setInterval(async function () {
|
||||||
|
waited += 4;
|
||||||
|
var g = await api("suggest_image_placements", { email: email, project_id: pid });
|
||||||
|
if (g.ok && !g.pending) { clearInterval(t); done(g); return; }
|
||||||
|
if (waited > 150) { clearInterval(t); done({ ok: false, error: "That is taking unusually long." }); }
|
||||||
|
}, 4000);
|
||||||
|
});
|
||||||
|
}
|
||||||
sg.disabled = false; sg.textContent = "Suggest where they fit";
|
sg.disabled = false; sg.textContent = "Suggest where they fit";
|
||||||
document.getElementById("sugnote").textContent = r.status_text || "";
|
document.getElementById("sugnote").textContent = r.status_text || "";
|
||||||
if (!r.ok) { showMsg("msg", r.error || "Could not suggest."); return; }
|
if (!r.ok) { showMsg("msg", r.error || "Could not suggest."); return; }
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue