Skip to content

Commit

Permalink
More service base class documentation
Browse files Browse the repository at this point in the history
Signed-off-by: Jim Easterbrook <jim@jim-easterbrook.me.uk>
  • Loading branch information
jim-easterbrook committed Aug 30, 2018
1 parent 1ca6652 commit e32d74f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/pywws/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__version__ = '18.8.0'
_release = '1615'
_commit = '2d5166d'
_release = '1616'
_commit = '1ca6652'
26 changes: 22 additions & 4 deletions src/pywws/service/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def append(self, x):
self._start()

def full(self):
"""Are there already too many uploads on the queue."""
return len(self) >= 50


Expand Down Expand Up @@ -212,10 +213,10 @@ class DataServiceBase(ServiceBase):
Data service classes must provide a :py:attr:`template` string to
define how to convert pywws data before uploading. Required methods
are :py:meth:`session` and :py:meth:`upload_data`. If the service
has a separate authorisation or registration process this can be
done in a :py:meth:`~pywws.service.mastodon.register` method. See
:py:mod:`pywws.service.mastodon` for an example.
are :py:meth:`~ServiceBase.session` and :py:meth:`upload_data`. If
the service has a separate authorisation or registration process
this can be done in a :py:meth:`~pywws.service.mastodon.register`
method. See :py:mod:`pywws.service.mastodon` for an example.
"""

template = ''
Expand Down Expand Up @@ -258,6 +259,23 @@ def __init__(self, context, check_params=True):
else:
self.last_update = datetime.min

def upload_data(self, session, prepared_data={}, live=False):
"""Upload one data set to the service.
Every data service class must implement this method.
:param object session: the object created by
:py:meth:`~ServiceBase.session`. This is typically used to
communicate with the server and is automatically closed when
a batch of uplaods has finished.
:param dict prepared_data: a set of key: value pairs to upload.
The keys and values must all be text strings.
:param bool live: is this set of data "live" or "logged". This
is used by :py:mod:`pywws.service.underground` to select the
server to use.
"""
raise NotImplementedError()

def queue_data(self, timestamp, data, live):
if timestamp and timestamp < self.last_update + self.interval:
return False
Expand Down

0 comments on commit e32d74f

Please sign in to comment.