compass.services.threaded.JurisdictionUpdater#
- class JurisdictionUpdater(jurisdiction_fp, tpe_kwargs=None)[source]#
Bases:
ThreadedServiceService that updates jurisdiction info into a file
- Parameters:
jurisdiction_fp (path-like) – Path to JSON file where jurisdictions should be tracked.
tpe_kwargs (
dict, optional) – Keyword-value argument pairs to pass toconcurrent.futures.ThreadPoolExecutor. By default,None.
Methods
Open thread pool and temp directory
call(*args, **kwargs)Call the service
process(jurisdiction, doc, seconds_elapsed)Record jurisdiction metadata in the tracking file
process_using_futures(fut, *args, **kwargs)Process a call to the service
Shutdown thread pool and cleanup temp directory
Attributes
Max number of concurrent job submissions.
Trueif file not currently being written toService name used to pull the correct queue object
- async process(jurisdiction, doc, seconds_elapsed, usage_tracker=None)[source]#
Record jurisdiction metadata in the tracking file
The file on disk is updated in-place.
- Parameters:
jurisdiction (
Jurisdiction) – The jurisdiction instance to record.doc (
elm.web.document.BaseDocumentorNone) – Document containing meta information about the jurisdiction. Must have relevant processing keys in theattrsdict, otherwise the jurisdiction may not be recorded properly. IfNone, the jurisdiction is assumed not to have been found.seconds_elapsed (
intorfloat) – Total number of seconds it took to look for (and possibly parse) this document.usage_tracker (
UsageTracker, optional) – Optional tracker instance to monitor token usage during LLM calls. By default,None.
- MAX_CONCURRENT_JOBS = 10000#
Max number of concurrent job submissions.
- acquire_resources()#
Open thread pool and temp directory
- async classmethod call(*args, **kwargs)#
Call the service
- Parameters:
*args – Positional and keyword arguments to be passed to the underlying service processing function.
**kwargs – Positional and keyword arguments to be passed to the underlying service processing function.
- Returns:
object– A response object from the underlying service.
- async process_using_futures(fut, *args, **kwargs)#
Process a call to the service
The result is communicated by updating
fut.- Parameters:
fut (
asyncio.Future) – A future object that should get the result of the processing operation. If the processing function returnsanswer, this method should callfut.set_result(answer).**kwargs – Keyword arguments to be passed to the underlying processing function.
- release_resources()#
Shutdown thread pool and cleanup temp directory