annals.overview#
Spoken overviews of a document: the request a page makes, and the worker that fulfils it.
A reader asks for an overview from a document’s page. That writes one small JSON file under
the data root (overviews/<doc id>.json). A worker on the same machine reads the document
from the store, runs a command that makes the overview, and publishes the result as a
document of its own. The page polls the request’s state.
annals does not know how an overview is made. The command is the seam: any program that
takes a text file and writes one HTML page, named in ANNALS_OVERVIEW_COMMAND or passed to
work(), with {source}, {minutes} and {out} filled in, and {url}, the source document’s
page, so the overview can link to what it was based on:
my-overview {source} --minutes {minutes} --player-to {out} --source-url {url}
The feature is off unless the host turns it on (mk_api(overviews=True)), because making
an overview spends money. A host can also offer it to some readers only
(mk_api(overviews={"me@example.com"}), or ANNALS_OVERVIEWS for annals.api.mk_app();
see readers_offered()): the others get no Listen button, and the documents the feature
makes (made_here()) are hidden from them. For the same reason, a current overview is not made again unless
forced, a crash after publishing does not pay twice, work stops at a daily limit, and a
request nobody fulfilled expires rather than spending money whenever a worker next wakes.
Run the worker on a timer. Finished request files stay in the folder and the worker writes there, so a watcher on the folder would keep waking it.
When the command cannot work until someone acts (an expired login, a voice account out of
credit), pressing again only spends the daily limit. So the worker notices it: the same
failure, fast, from two documents in a row, marks the maker down with that reason (a
document failing twice is that document). An agent can mark it too, with a link to where it
is being fixed (annals listen-down "why" --link URL). While it is down, nothing fails or
is dropped: requests wait (past the daily limit too), the page says why and what to do
instead of offering a Try again, and the worker tries one of them again every few hours. The
first success, or annals listen-down --clear, clears the mark and queues everything that
waited.
>>> html_to_text("<title>x</title><p>One & two</p><script>no()</script><p>Three</p>")
'One & two\n\nThree'
>>> [c["characters"] for c in choices()]
[2700, 4500, 6300]
Module Attributes
in |
|
in |
|
read by the server and the worker, which may be different users |
|
at most this many overviews are started in any 24 hours, whoever asks |
|
nobody is waiting for it now |
|
a request still running after this long has lost its worker |
|
the file marking the maker down; not |
|
the same fast failure from this many documents in a row means the maker is down |
|
the maker could not start |
|
while the maker is down, one waiting request is tried this often, to notice it works again |
|
the lengths a reader can pick, in minutes; each costs voice characters, so the set is closed |
|
spoken English at about 150 words a minute and 6 characters a word; shown as an estimate |
|
marks a document that is itself an overview, so nobody makes an overview of an overview |
|
made once it works again, never spent on before |
|
a failed request is still listed as unmade for this long, so a retry is offered where the reader looks for the overview (the Audio tab), not only on the document |
|
marks a document made by putting several documents' text in one, for one review of them all |
|
a queued combination is filed under this plus its |
|
the |
Functions
|
Each length on offer and what it would cost in voice characters. |
|
One document holding the text of |
|
Names a set of documents at their current versions, in any order. |
|
The id a queued combination is filed under, before its document exists. |
|
Whether a document can be spoken: readable text, current, and not itself an overview. |
|
The combined document made for |
|
The readable text of a page: no markup, scripts or styles (nor its PDF button). |
|
Whether the overview feature made this document: a spoken overview, or the text it combined to speak several documents as one. |
|
Why no overview can be made until someone acts, or |
|
Say the maker is down, why, and where it is being fixed; keep what is not given. |
|
The maker works (again): clear the mark and queue what waited; return those ids. |
|
Who may ask for and hear overviews: |
|
Ask for an overview of a document. |
|
Ask for ONE overview of several documents: of the document combining their text. |
|
What a page shows for a document: its request's state and what it can start. |
|
The overviews asked for and not (yet) made: being made, waiting, or failed recently. |
|
Whether this is a length on offer. |
|
Fulfil every queued request, one at a time, until none is left; return what happened. |
Classes
|
The request files: one per document, each replaced whole so a reader never sees half. |
Exceptions
The overview command ran and failed: the maker's fault, not the document's. |
- annals.overview.CHARS_PER_MINUTE = 900#
spoken English at about 150 words a minute and 6 characters a word; shown as an estimate
- annals.overview.COMBINED_REQUEST_PREFIX = 'combined-'#
a queued combination is filed under this plus its
combined_key(), until it has a document
- annals.overview.COMBINED_TAG = 'combined'#
marks a document made by putting several documents’ text in one, for one review of them all
- annals.overview.COMBINE_KIND = 'combine'#
the
kindof a request record for a combination (the only marker; the id is a file name)
- annals.overview.DFLT_DAILY_LIMIT = 20#
at most this many overviews are started in any 24 hours, whoever asks
- annals.overview.DOWN_AFTER = 2#
the same fast failure from this many documents in a row means the maker is down
- annals.overview.DOWN_FILE = 'maker-down'#
the file marking the maker down; not
.json, because every.jsonhere is a request
- annals.overview.ENV_OVERVIEWS = 'ANNALS_OVERVIEWS'#
-
- Type:
who is offered overviews, for a host built from the environment
- annals.overview.EVERY_READER = '*'#
in
ANNALS_OVERVIEWS, the readers are separated by this;*alone means every reader
- annals.overview.FAILED_SHOWN_S = 604800#
a failed request is still listed as unmade for this long, so a retry is offered where the reader looks for the overview (the Audio tab), not only on the document
- annals.overview.FAST_FAILURE_S = 120#
the maker could not start
- Type:
a failure this quick never reached the work
- annals.overview.MINUTES = (3, 5, 7)#
the lengths a reader can pick, in minutes; each costs voice characters, so the set is closed
- exception annals.overview.MakerFailed[source]#
Bases:
RuntimeErrorThe overview command ran and failed: the maker’s fault, not the document’s.
- annals.overview.PROBE_EVERY_S = 10800#
while the maker is down, one waiting request is tried this often, to notice it works again
- annals.overview.QUEUED_EXPIRY_S = 3600#
nobody is waiting for it now
- Type:
a request still queued after this long is dropped
- annals.overview.READERS_SEP = ','#
in
ANNALS_OVERVIEWS, the readers are separated by this;*alone means every reader
- annals.overview.REQUEST_FILE_MODE = 420#
read by the server and the worker, which may be different users
- Type:
request files and the down mark
- annals.overview.RUNNING_MARGIN_S = 600#
a request still running after this long has lost its worker
- class annals.overview.Requests(data_dir)[source]#
Bases:
objectThe request files: one per document, each replaced whole so a reader never sees half.
- mark()[source]#
What the worker knows of the maker’s recent failures (see
maker_down()).- Return type:
- annals.overview.TAG = 'overview'#
marks a document that is itself an overview, so nobody makes an overview of an overview
- annals.overview.WAITING = 'waiting'#
made once it works again, never spent on before
- Type:
asked for while the maker is down
- annals.overview.combined_document(store, docs, *, title, group=None, max_bytes=None)[source]#
One document holding the text of
docs, so a review of it covers them all.A combined document among
docscounts as the documents it combines. The same documents at the same versions give the same document back, so asking twice makes one. A new one is added togroupwhen given. RaisesValueErrorwhen none ofdocshas text to speak, or pastmax_bytesof text.- Return type:
- annals.overview.combined_key(docs)[source]#
Names a set of documents at their current versions, in any order.
>>> combined_key([{"id": "b", "version": 2}, {"id": "a"}]) == combined_key([{"id": "a"}, {"id": "b", "version": 2}]) True
- Return type:
- annals.overview.combined_request_id(key)[source]#
The id a queued combination is filed under, before its document exists.
- Return type:
- annals.overview.eligible(meta)[source]#
Whether a document can be spoken: readable text, current, and not itself an overview.
- Return type:
- annals.overview.find_combined(store, key)[source]#
The combined document made for
key(combined_key()), if there is one.
- annals.overview.html_to_text(html)[source]#
The readable text of a page: no markup, scripts or styles (nor its PDF button).
- Return type:
- annals.overview.made_here(meta)[source]#
Whether the overview feature made this document: a spoken overview, or the text it combined to speak several documents as one. These are what a reader who is not offered overviews never sees.
- Return type:
- annals.overview.maker_down(requests)[source]#
Why no overview can be made until someone acts, or
Nonewhile the maker works.{"reason", "since", "link"}: in words, from when, and where it is being fixed (orNone). Set by the worker once the same fast failure came fromDOWN_AFTERdocuments in a row, or by hand withmark_down(); cleared by the next success ormark_up().
- annals.overview.mark_down(requests, reason='', *, link=None)[source]#
Say the maker is down, why, and where it is being fixed; keep what is not given.
For an agent that filed the task that would fix it: the page then links to it. A link alone only adds to a mark that is already there. Raises
ValueErrorotherwise, or for a link that is not a web address.- Return type:
- annals.overview.mark_up(requests)[source]#
The maker works (again): clear the mark and queue what waited; return those ids.
- annals.overview.readers_offered(spec)[source]#
Who may ask for and hear overviews:
False(nobody),True(every reader), or a test.specis what a host passes asoverviews: a bool, a predicate on the reader’s name (an email, asannals.api.reader_of()gives it), a collection of names, or a string asANNALS_OVERVIEWSholds it (names separated by commas,*for every reader, empty for nobody;true/1/yesandfalse/0/nomean the same as*and empty, never a reader so named). Names are compared without case.>>> readers_offered("*"), readers_offered(""), readers_offered(None) (True, False, False) >>> readers_offered("true"), readers_offered(" No "), readers_offered(["*"]) (True, False, True) >>> may = readers_offered(" Me@Example.com, ") >>> may("me@example.com"), may("someone@example.com") (True, False)
- annals.overview.request(store, requests, doc_id, *, minutes=5, force=False)[source]#
Ask for an overview of a document. Raises
ValueErrorif it cannot be asked for.Asking again while one is being made changes nothing, and neither does asking for one that exists and is current unless
force, so a repeat costs nothing. While the maker is down (maker_down()), the request waits for it rather than failing.- Return type:
- annals.overview.request_combined(store, requests, docs, *, title, group=None, minutes=5, max_bytes=None)[source]#
Ask for ONE overview of several documents: of the document combining their text.
Nothing is published here. When the documents were combined before, that document gets an ordinary request. Otherwise the request is queued, with the document ids, under
combined_request_id()(a record markedkind: "combine"), and the worker makes the combined document (seecombined_document()) when it starts the job, so a request nobody works leaves no document behind. Returns{"doc": <combined document id, or None until the worker has made it>, "listen": <the overview's state>}. RaisesValueErrorasrequest()does, or when there is nothing to speak or too much of it: refused now, not after the request has waited for a worker.The key names the documents at their versions now. A retry after one of them changed is a different key, so a new request: the old failed one stays listed until it expires.
- Return type:
- annals.overview.state_of(store, requests, meta)[source]#
What a page shows for a document: its request’s state and what it can start.
- Return type:
- annals.overview.unmade(store, requests)[source]#
The overviews asked for and not (yet) made: being made, waiting, or failed recently.
Each is
state_ofits document plusdoc,title,created(the document’s),requestedandfinished(the last try’s). A queued combination of several documents has no document yet:docisNoneandcombinehas thedocsandgroupto ask again with (POST /overviews). A request whose document is gone, binned or no longer speakable is left out: nothing can be retried. Newest first.
- annals.overview.valid_minutes(minutes)[source]#
Whether this is a length on offer. Exactly an int: not
True, and not3.0.- Return type:
- annals.overview.work(store, requests, *, command=None, timeout=1800, daily_limit=None, doc_url=<class 'str'>)[source]#
Fulfil every queued request, one at a time, until none is left; return what happened.
A failure is recorded on its request, for the page to show, and the next one still runs. A request made while this runs is picked up before it exits.
doc_urlturns a document id into its page, for{url}. While the maker is down, requests wait, and one of them is tried everyPROBE_EVERY_S; once one works, those waiting run too.