mirror of
https://github.com/ArchipelagoMW/Archipelago.git
synced 2026-03-07 23:25:51 -08:00
Compare commits
3 Commits
webhost_ro
...
webhost_qu
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1169e62191 | ||
|
|
d0bd1d29b1 | ||
|
|
d463faa9d9 |
@@ -1,15 +1,16 @@
|
||||
import json
|
||||
import typing
|
||||
from uuid import UUID
|
||||
|
||||
from flask import request, session, url_for
|
||||
from markupsafe import Markup
|
||||
from pony.orm import commit
|
||||
from pony.orm import commit, select
|
||||
|
||||
from Utils import restricted_dumps
|
||||
from WebHostLib import app
|
||||
from WebHostLib import app, cache
|
||||
from WebHostLib.check import get_yaml_data, roll_options
|
||||
from WebHostLib.generate import get_meta
|
||||
from WebHostLib.models import Generation, STATE_QUEUED, Seed, STATE_ERROR
|
||||
from WebHostLib.models import Generation, STATE_QUEUED, STATE_STARTED, Seed, STATE_ERROR
|
||||
from . import api_endpoints
|
||||
|
||||
|
||||
@@ -74,12 +75,23 @@ def generate_api():
|
||||
def wait_seed_api(seed: UUID):
|
||||
seed_id = seed
|
||||
seed = Seed.get(id=seed_id)
|
||||
reply_dict: dict[str, typing.Any] = {"queue_len": get_queue_length()}
|
||||
if seed:
|
||||
return {"text": "Generation done"}, 201
|
||||
reply_dict["text"] = "Generation done"
|
||||
return reply_dict, 201
|
||||
generation = Generation.get(id=seed_id)
|
||||
|
||||
if not generation:
|
||||
return {"text": "Generation not found"}, 404
|
||||
reply_dict["text"] = "Generation not found"
|
||||
return reply_dict, 404
|
||||
elif generation.state == STATE_ERROR:
|
||||
return {"text": "Generation failed"}, 500
|
||||
return {"text": "Generation running"}, 202
|
||||
reply_dict["text"] = "Generation failed"
|
||||
return reply_dict, 500
|
||||
reply_dict["text"] = "Generation running"
|
||||
return reply_dict, 202
|
||||
|
||||
|
||||
@cache.memoize(timeout=5)
|
||||
def get_queue_length() -> int:
|
||||
return select(generation for generation in Generation if
|
||||
generation.state == STATE_STARTED or generation.state == STATE_QUEUED).count()
|
||||
|
||||
@@ -30,10 +30,21 @@
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
waitSeedDiv.innerHTML = `
|
||||
<h1>Generation in Progress</h1>
|
||||
<p>${data.text}</p>
|
||||
`;
|
||||
if (data.queue_len === 1){
|
||||
waitSeedDiv.innerHTML = `
|
||||
<h1>Generation in Progress</h1>
|
||||
<p>${data.text}</p>
|
||||
<p>This is the only generation in the queue.</p>
|
||||
`;
|
||||
}
|
||||
else {
|
||||
waitSeedDiv.innerHTML = `
|
||||
<h1>Generation in Progress</h1>
|
||||
<p>${data.text}</p>
|
||||
<p>There are ${data.queue_len} generations in the queue.</p>
|
||||
`;
|
||||
}
|
||||
|
||||
|
||||
setTimeout(checkStatus, 1000); // Continue polling.
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user