Skip to content

Commit

Permalink
Fix docs which were broken after last version change (#21)
Browse files Browse the repository at this point in the history
Also:
* add caching
* build docs with tests so failures are caught
  • Loading branch information
maroux committed Oct 4, 2018
1 parent e90c048 commit 65ffe98
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 15 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ matrix:
- python: 3.7
dist: xenial
sudo: true
cache: pip
install:
- make test_setup
script:
Expand Down
10 changes: 9 additions & 1 deletion docs/api.rst
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
API reference
=============

.. module:: hedwig
.. module:: hedwig.consumer

.. autofunction:: listen_for_messages
.. autofunction:: process_messages_for_lambda_consumer

.. module:: hedwig.models

.. autoclass:: Message
:members: new, publish, data_schema_version, id, schema, type, format_version, metadata, timestamp, headers,
receipt, publisher, data, topic, validate, extend_visibility_timeout
Expand All @@ -19,15 +21,21 @@ API reference

.. autoclass:: MessageType

.. module:: hedwig.validator

.. autoclass:: MessageValidator
:members: checker, validate
:undoc-members:

.. module:: hedwig.commands

.. autofunction:: requeue_dead_letter

Exceptions
++++++++++

.. module:: hedwig.exceptions

.. autoclass:: RetryException
.. autoclass:: IgnoreException
.. autoclass:: ValidationError
Expand Down
6 changes: 3 additions & 3 deletions docs/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,15 @@ To use hedwig, simply add a message handler like so:

.. code:: python
def send_email(message: hedwig.Message) -> None:
def send_email(message: hedwig.models.Message) -> None:
# send email
And then send a message:

.. code:: python
message = hedwig.Message.new(
hedwig.MessageType.send_email,
message = hedwig.models.Message.new(
hedwig.models.MessageType.send_email,
StrictVersion('1.0'),
{
'to': 'example@email.com',
Expand Down
Empty file removed docs/schema.rst
Empty file.
6 changes: 3 additions & 3 deletions docs/settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,19 @@ optional; string

**HEDWIG_DATA_VALIDATOR_CLASS**

The validator class to use for schema validation. This class must be a sub-class of :class:`hedwig.MessageValidator`,
The validator class to use for schema validation. This class must be a sub-class of :class:`hedwig.validator.MessageValidator`,
and may add additional validation logic, based on pyjsonschema_ docs.

For example, to add a new format called ``vin``, use this validator:

.. code:: python
class CustomValidator(hedwig.MessageValidator):
class CustomValidator(hedwig.validator.MessageValidator):
# simplistic check: 17 alphanumeric characters except i, o, q
_vin_re = re.compile("^[a-hj-npr-z0-9]{17}$")
@staticmethod
@hedwig.MessageValidator.checker.checks('vin')
@hedwig.models.MessageValidator.checker.checks('vin')
def check_vin(instance) -> bool:
if not isinstance(instance, str):
return True
Expand Down
12 changes: 6 additions & 6 deletions docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ Usage Guide
Callbacks
+++++++++

Callbacks are simple python functions that accept a single argument of type ``hedwig.Message`` -
Callbacks are simple python functions that accept a single argument of type ``hedwig.models.Message`` -

.. code:: python
def send_email(message: hedwig.Message) -> None:
def send_email(message: hedwig.models.Message) -> None:
# send email
You can access the data dict using ``message.data`` as well as custom headers using ``message.headers`` and other
metadata fields as described in the API docs: :meth:`hedwig.Message`.
metadata fields as described in the API docs: :meth:`hedwig.models.Message`.

Publisher
+++++++++
Expand All @@ -21,7 +21,7 @@ You can run publish messages like so:

.. code:: python
Message.new(MessageType.my_message, StrictVersion('1.0'), data).publish()
models.Message.new(MessageType.my_message, StrictVersion('1.0'), data).publish()
If you want to include a custom headers with the message (for example, you can include a ``request_id`` field for
cross-application tracing), you can pass in additional parameter ``headers``.
Expand All @@ -33,15 +33,15 @@ A consumer for SQS based workers can be started as following:

.. code:: python
hedwig.listen_for_messages()
consumer.listen_for_messages()
This is a blocking function. Don't use threads since this library is **NOT** guaranteed to be thread-safe.

A consumer for Lambda based workers can be started as following:

.. code:: python
hedwig.process_messages_for_lambda_consumer(lambda_event)
consumer.process_messages_for_lambda_consumer(lambda_event)
where ``lambda_event`` is the event provided by AWS to your Lambda function as described in `lambda sns format`_.

Expand Down
7 changes: 5 additions & 2 deletions scripts/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@ fi

options="${target} ${options}"

black --skip-string-normalization --skip-numeric-underscore-normalization --line-length=120 --check .

mypy hedwig

# make sure hedwig can be imported without SETTINGS_MODULE set
python3 -c 'import hedwig'

python3 -bb -m pytest ${options}

black --skip-string-normalization --skip-numeric-underscore-normalization --line-length=120 --check .

flake8

pip install -e .
make docs

0 comments on commit 65ffe98

Please sign in to comment.