Spaces:
Sleeping
Sleeping
CraterView.ai commited on
Commit ·
5d0bf62
1
Parent(s): b3d9ede
Ask a photo's upload once more when the first ask got no answer
Browse files- following.py +18 -8
- space.py +3 -3
following.py
CHANGED
|
@@ -2,8 +2,9 @@
|
|
| 2 |
can be read and tested without it.
|
| 3 |
|
| 4 |
A visitor's run holds one of the demo's places while it has work on the account, taken and given
|
| 5 |
-
back in one place, so no path through a run can keep one. A
|
| 6 |
-
|
|
|
|
| 7 |
it has seen with the job it made, so a job made by an ask whose answer was lost is the job the
|
| 8 |
page goes on to follow. The page asks after each job until
|
| 9 |
it settles, to show the result. A job nobody is waiting for any more, because the visitor's wait
|
|
@@ -67,18 +68,27 @@ def busy(failure: BaseException) -> bool:
|
|
| 67 |
return isinstance(failure, CraterViewError) and only_a_wait(failure)
|
| 68 |
|
| 69 |
|
| 70 |
-
def sent(cv, model: str,
|
| 71 |
-
"""The job a
|
| 72 |
-
|
| 73 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
key = new_idempotency_key()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
try:
|
| 76 |
-
return
|
| 77 |
except CraterViewError as failure:
|
| 78 |
if not unanswered(failure):
|
| 79 |
raise
|
| 80 |
time.sleep(pause)
|
| 81 |
-
return
|
| 82 |
|
| 83 |
|
| 84 |
def settled(cv, job, *, poll: float, give_up_after: float,
|
|
|
|
| 2 |
can be read and tested without it.
|
| 3 |
|
| 4 |
A visitor's run holds one of the demo's places while it has work on the account, taken and given
|
| 5 |
+
back in one place, so no path through a run can keep one. A photo's upload is asked once more
|
| 6 |
+
when the first ask got no answer, and a job is sent under one idempotency key and asked once
|
| 7 |
+
more under it the same way: the platform answers a key
|
| 8 |
it has seen with the job it made, so a job made by an ask whose answer was lost is the job the
|
| 9 |
page goes on to follow. The page asks after each job until
|
| 10 |
it settles, to show the result. A job nobody is waiting for any more, because the visitor's wait
|
|
|
|
| 68 |
return isinstance(failure, CraterViewError) and only_a_wait(failure)
|
| 69 |
|
| 70 |
|
| 71 |
+
def sent(cv, model: str, photo, params: dict, *, pause: float):
|
| 72 |
+
"""The job a photo makes: the photo uploaded, then submitted under one idempotency key.
|
| 73 |
+
Each request is asked once more, `pause` seconds later, when the first ask was unanswered.
|
| 74 |
+
An upload asked twice leaves at most an unused upload, which expires on its own; a
|
| 75 |
+
submission asked twice under one key makes one job. A connection the platform closed while
|
| 76 |
+
the Space sat idle fails the first request on it with no answer, so this is also what a
|
| 77 |
+
visitor who chose a photo and waited before pressing the button meets. A refusal is raised
|
| 78 |
+
at once, and so is the second ask's failure, as the client's own `run()` does."""
|
| 79 |
+
input_key = _asked_twice(lambda: cv.upload(photo), pause)
|
| 80 |
key = new_idempotency_key()
|
| 81 |
+
return _asked_twice(lambda: cv.submit(model, input_key, idempotency_key=key, **params), pause)
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
def _asked_twice(ask: Callable, pause: float):
|
| 85 |
try:
|
| 86 |
+
return ask()
|
| 87 |
except CraterViewError as failure:
|
| 88 |
if not unanswered(failure):
|
| 89 |
raise
|
| 90 |
time.sleep(pause)
|
| 91 |
+
return ask()
|
| 92 |
|
| 93 |
|
| 94 |
def settled(cv, job, *, poll: float, give_up_after: float,
|
space.py
CHANGED
|
@@ -49,7 +49,7 @@ Image.MAX_IMAGE_PIXELS = None
|
|
| 49 |
HERE = Path(__file__).parent
|
| 50 |
SLOTS = 2 # photos in flight at once, across every visitor
|
| 51 |
POLL_SECONDS = 2.0
|
| 52 |
-
RESUBMIT_SECONDS = 2.0 # before a submission that got no answer is asked again
|
| 53 |
GIVE_UP_SECONDS = 3600 # how long a job is followed before its place is given back
|
| 54 |
FOLLOW_UP_SECONDS = 60.0 # how often a job nobody waits for is asked after, to delete it
|
| 55 |
PREVIEW_SIDE = 1400 # the photo as drawn on the page
|
|
@@ -212,7 +212,7 @@ def _told(failure: BaseException, otherwise: str) -> str:
|
|
| 212 |
def _first_step(run: Run, model: str, photo: Path, params: dict, submitted: list[str]) -> None:
|
| 213 |
run.status = "sending"
|
| 214 |
try:
|
| 215 |
-
job = following.sent(cv, model,
|
| 216 |
except (CraterViewError, OSError) as failure:
|
| 217 |
# The account's own limits, and a platform that did not answer, are not the visitor's
|
| 218 |
# to read about. A refusal is said in the platform's own words.
|
|
@@ -251,7 +251,7 @@ def _second_step(run: Run, submitted: list[str]) -> None:
|
|
| 251 |
so a second step that fails leaves the visitor with it and says so, not with nothing."""
|
| 252 |
run.step, run.status, run.eta_seconds = 2, "sending", None
|
| 253 |
try:
|
| 254 |
-
job = following.sent(cv, run.then.model,
|
| 255 |
pause=RESUBMIT_SECONDS)
|
| 256 |
except (CraterViewError, OSError) as failure:
|
| 257 |
# The account's own limits, and a platform that did not answer, are not the visitor's
|
|
|
|
| 49 |
HERE = Path(__file__).parent
|
| 50 |
SLOTS = 2 # photos in flight at once, across every visitor
|
| 51 |
POLL_SECONDS = 2.0
|
| 52 |
+
RESUBMIT_SECONDS = 2.0 # before an upload or a submission that got no answer is asked again
|
| 53 |
GIVE_UP_SECONDS = 3600 # how long a job is followed before its place is given back
|
| 54 |
FOLLOW_UP_SECONDS = 60.0 # how often a job nobody waits for is asked after, to delete it
|
| 55 |
PREVIEW_SIDE = 1400 # the photo as drawn on the page
|
|
|
|
| 212 |
def _first_step(run: Run, model: str, photo: Path, params: dict, submitted: list[str]) -> None:
|
| 213 |
run.status = "sending"
|
| 214 |
try:
|
| 215 |
+
job = following.sent(cv, model, photo, params, pause=RESUBMIT_SECONDS)
|
| 216 |
except (CraterViewError, OSError) as failure:
|
| 217 |
# The account's own limits, and a platform that did not answer, are not the visitor's
|
| 218 |
# to read about. A refusal is said in the platform's own words.
|
|
|
|
| 251 |
so a second step that fails leaves the visitor with it and says so, not with nothing."""
|
| 252 |
run.step, run.status, run.eta_seconds = 2, "sending", None
|
| 253 |
try:
|
| 254 |
+
job = following.sent(cv, run.then.model, run.result, run.then_params,
|
| 255 |
pause=RESUBMIT_SECONDS)
|
| 256 |
except (CraterViewError, OSError) as failure:
|
| 257 |
# The account's own limits, and a platform that did not answer, are not the visitor's
|