From 5d6d37785e347760ed5f8c57efa784210f651729 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Wed, 20 Sep 2023 23:53:12 +0200 Subject: [PATCH] [#288] Removed legacy `http.poll` backend. Closes: #288 --- docs/source/backends.rst | 1 - docs/source/platypush/backend/http.poll.rst | 6 -- platypush/backend/http/poll/__init__.py | 88 --------------------- platypush/backend/http/poll/manifest.yaml | 6 -- 4 files changed, 101 deletions(-) delete mode 100644 docs/source/platypush/backend/http.poll.rst delete mode 100644 platypush/backend/http/poll/__init__.py delete mode 100644 platypush/backend/http/poll/manifest.yaml diff --git a/docs/source/backends.rst b/docs/source/backends.rst index 5e2f1c498..d4541d932 100644 --- a/docs/source/backends.rst +++ b/docs/source/backends.rst @@ -21,7 +21,6 @@ Backends platypush/backend/google.pubsub.rst platypush/backend/gps.rst platypush/backend/http.rst - platypush/backend/http.poll.rst platypush/backend/inotify.rst platypush/backend/joystick.rst platypush/backend/joystick.jstest.rst diff --git a/docs/source/platypush/backend/http.poll.rst b/docs/source/platypush/backend/http.poll.rst deleted file mode 100644 index 861fe1be4..000000000 --- a/docs/source/platypush/backend/http.poll.rst +++ /dev/null @@ -1,6 +0,0 @@ -``http.poll`` -=============================== - -.. automodule:: platypush.backend.http.poll - :members: - diff --git a/platypush/backend/http/poll/__init__.py b/platypush/backend/http/poll/__init__.py deleted file mode 100644 index 49f33b46d..000000000 --- a/platypush/backend/http/poll/__init__.py +++ /dev/null @@ -1,88 +0,0 @@ -import importlib -import time - -from platypush.backend import Backend -from platypush.backend.http.request import HttpRequest - - -class HttpPollBackend(Backend): - """ - WARNING: This integration is deprecated, since it was practically only used for RSS subscriptions. - RSS feeds integration has been replaced by :class:`platypush.plugins.rss.RSSPlugin`. - - This backend will poll multiple HTTP endpoints/services and return events - the bus whenever something new happened. Supported types: - :class:`platypush.backend.http.request.JsonHttpRequest` (for polling updates on - a JSON endpoint), :class:`platypush.backend.http.request.rss.RssUpdates` - (for polling updates on an RSS feed). Example configuration:: - - backend.http.poll: - requests: - - - # Poll for updates on a JSON endpoint - method: GET - type: platypush.backend.http.request.JsonHttpRequest - args: - url: https://host.com/api/v1/endpoint - headers: - Token: TOKEN - params: - updatedSince: 1m - timeout: 5 # Times out after 5 seconds (default) - poll_seconds: 60 # Check for updates on this endpoint every 60 seconds (default) - path: ${response['items']} # Path in the JSON to check for new items. - # Python expressions are supported. - # Note that 'response' identifies the JSON root. - # Default value: JSON root. - - - # Poll for updates on an RSS feed - type: platypush.backend.http.request.rss.RssUpdates - url: https://www.theguardian.com/rss/world - title: The Guardian - World News - poll_seconds: 120 - max_entries: 10 - - Triggers: an update event for the relevant HTTP source if it contains new items. For example: - - * :class:`platypush.message.event.http.rss.NewFeedEvent` if a feed contains new items - * :class:`platypush.message.event.http.HttpEvent` if a JSON endpoint contains new items - """ - - def __init__(self, requests, *args, **kwargs): - """ - :param requests: Configuration of the requests to make (see class description for examples) - :type requests: dict - """ - - super().__init__(*args, **kwargs) - self.requests = [] - - for request in requests: - if isinstance(request, dict): - req_type = request['type'] - (module, name) = ('.'.join(req_type.split('.')[:-1]), req_type.split('.')[-1]) - module = importlib.import_module(module) - request = getattr(module, name)(**request) - elif not isinstance(request, HttpRequest): - raise RuntimeError('Request should either be a dict or a ' + - 'HttpRequest object, {} found'.format(type(request))) - - request.bus = self.bus - self.requests.append(request) - - def run(self): - super().run() - - while not self.should_stop(): - for request in self.requests: - if time.time() - request.last_request_timestamp > request.poll_seconds: - try: - request.execute() - except Exception as e: - self.logger.error('Error while executing request: {}'.format(request)) - self.logger.exception(e) - - time.sleep(0.1) # Prevent a tight loop - - -# vim:sw=4:ts=4:et: diff --git a/platypush/backend/http/poll/manifest.yaml b/platypush/backend/http/poll/manifest.yaml deleted file mode 100644 index fb5b0a2d3..000000000 --- a/platypush/backend/http/poll/manifest.yaml +++ /dev/null @@ -1,6 +0,0 @@ -manifest: - events: {} - install: - pip: [] - package: platypush.backend.http.poll - type: backend