Coverage for /usr/local/lib/python3.10/site-packages/opal_common-0.0.0-py3.10.egg/opal_common/fetcher/engine/base_fetching_engine.py: 64%

22 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-10-10 11:54 +0000

1from typing import Coroutine 

2 

3from opal_common.fetcher.engine.core_callbacks import OnFetchFailureCallback 

4from opal_common.fetcher.events import FetcherConfig, FetchEvent 

5from opal_common.fetcher.fetcher_register import FetcherRegister 

6 

7 

8class BaseFetchingEngine: 

9 """An interface base class for a task queue manager used for fetching 

10 events.""" 

11 

12 @property 

13 def register(self) -> FetcherRegister: 

14 """Access to the underlying fetcher providers register.""" 

15 raise NotImplementedError() 

16 

17 async def __aenter__(self): 

18 """Async Context manager to cancel tasks on exit.""" 

19 raise NotImplementedError() 

20 

21 async def __aexit__(self, exc_type, exc, tb): 

22 raise NotImplementedError() 

23 

24 async def terminate_tasks(self): 

25 """Cancel and wait on the internal worker tasks.""" 

26 raise NotImplementedError() 

27 

28 async def queue_url( 

29 self, 

30 url: str, 

31 callback: Coroutine, 

32 config: FetcherConfig = None, 

33 fetcher="HttpFetchProvider", 

34 ) -> FetchEvent: 

35 """Simplified default fetching handler for queuing a fetch task. 

36 

37 Args: 

38 url (str): the URL to fetch from 

39 callback (Coroutine): a callback to call with the fetched result 

40 config (FetcherConfig, optional): Configuration to be used by the fetcher. Defaults to None. 

41 fetcher (str, optional): Which fetcher class to use. Defaults to "HttpFetchProvider". 

42 Returns: 

43 the queued event (which will be mutated to at least have an Id) 

44 """ 

45 raise NotImplementedError() 

46 

47 async def queue_fetch_event( 

48 self, event: FetchEvent, callback: Coroutine 

49 ) -> FetchEvent: 

50 """Basic handler to queue a fetch event for a fetcher class. Waits if 

51 the queue is full. 

52 

53 Args: 

54 event (FetchEvent): the fetch event to queue as a task 

55 callback (Coroutine): a callback to call with the fetched result 

56 Returns: 

57 the queued event (which will be mutated to at least have an Id) 

58 """ 

59 raise NotImplementedError() 

60 

61 def register_failure_handler(self, callback: OnFetchFailureCallback): 

62 """Register a callback to be called with exception and original event 

63 in case of failure. 

64 

65 Args: 

66 callback (OnFetchFailureCallback): callback to register 

67 """ 

68 raise NotImplementedError() 

69 

70 async def _on_failure(self, error: Exception, event: FetchEvent): 

71 """Call event failure subscribers. 

72 

73 Args: 

74 error (Exception): thrown exception 

75 event (FetchEvent): event which was being handled 

76 """ 

77 raise NotImplementedError()