Base class defining the interface for a work queue.
| 21 | |
| 22 | |
| 23 | class WorkQueue(abc.ABC): |
| 24 | """ |
| 25 | Base class defining the interface for a work queue. |
| 26 | """ |
| 27 | |
| 28 | @abc.abstractmethod |
| 29 | async def populate_queue(self, work_paths: List[str], items_per_group: int) -> None: |
| 30 | """ |
| 31 | Add new items to the work queue. The specifics will vary depending on |
| 32 | whether this is a local or S3-backed queue. |
| 33 | |
| 34 | Args: |
| 35 | work_paths: Each individual path that we will process over |
| 36 | items_per_group: Number of items to group together in a single work item |
| 37 | """ |
| 38 | pass |
| 39 | |
| 40 | @abc.abstractmethod |
| 41 | async def initialize_queue(self) -> int: |
| 42 | """ |
| 43 | Load the work queue from the relevant store (local or remote) |
| 44 | and initialize it for processing. |
| 45 | |
| 46 | For example, this might remove already completed work items and randomize |
| 47 | the order before adding them to an internal queue. |
| 48 | """ |
| 49 | pass |
| 50 | |
| 51 | @abc.abstractmethod |
| 52 | async def is_completed(self, work_hash: str) -> bool: |
| 53 | """ |
| 54 | Check if a work item has been completed. |
| 55 | |
| 56 | Args: |
| 57 | work_hash: Hash of the work item to check |
| 58 | |
| 59 | Returns: |
| 60 | True if the work is completed, False otherwise |
| 61 | """ |
| 62 | pass |
| 63 | |
| 64 | @abc.abstractmethod |
| 65 | async def get_work(self, worker_lock_timeout_secs: int = 1800) -> Optional[WorkItem]: |
| 66 | """ |
| 67 | Get the next available work item that isn't completed or locked. |
| 68 | |
| 69 | Args: |
| 70 | worker_lock_timeout_secs: Number of seconds before considering |
| 71 | a worker lock stale (default 30 mins) |
| 72 | |
| 73 | Returns: |
| 74 | WorkItem if work is available, None if queue is empty |
| 75 | """ |
| 76 | pass |
| 77 | |
| 78 | @abc.abstractmethod |
| 79 | async def mark_done(self, work_item: WorkItem) -> None: |
| 80 | """ |
nothing calls this directly
no outgoing calls
no test coverage detected