Skip to content

Commit

Permalink
Merge pull request #6 from epidemicsound/refinements
Browse files Browse the repository at this point in the history
Liveness callback and raise on missing environment variable
  • Loading branch information
FreddeR authored Jul 1, 2019
2 parents 1fc3387 + bd41be8 commit 8d52a32
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ This module exposes the necessary API to create a worker which starts polling me
We can install the library through github by writing the dependency in `requirements.txt` as:

```
https://github.com/epidemicsound/aws-sqs-worker/releases/download/v0.0.1/aws_sqs_worker-0.0.1-py3-none-any.whl
https://github.com/epidemicsound/aws-sqs-worker/releases/download/v0.0.2/aws_sqs_worker-0.0.2-py3-none-any.whl
```

Replace 0.0.1 with the desired version, on both places in the url!
Replace 0.0.2 with the desired version, on both places in the url!

If using pipenv, you can also run `pipenv install https://github.com/epidemicsound/aws-sqs-worker/releases/download/v0.0.1/aws_sqs_worker-0.0.1-py3-none-any.whl`.
If using pipenv, you can also run `pipenv install https://github.com/epidemicsound/aws-sqs-worker/releases/download/v0.0.2/aws_sqs_worker-0.0.2-py3-none-any.whl`.

## Steps necessary to create a worker for the process:

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name='aws-sqs-worker',
version='0.0.1',
version='0.0.2',
description='AWS SQS Worker Module',
license='MIT',
long_description=long_description,
Expand Down
10 changes: 9 additions & 1 deletion worker/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,15 @@


class QueueServiceWorker:
def __init__(self, queue_name, handler, logger):
def __init__(self, queue_name, handler, logger, liveness_callback=None):
self.queue_name = queue_name
self.handler = handler
self.logger = logger
self.liveness_callback = liveness_callback

if settings.QUEUE_SERVICE_HOST is None:
raise Exception("aws-sqs-worker is missing a 'QUEUE_SERVICE_HOST' environment variable")

self.client = request_client.Client(settings.QUEUE_SERVICE_HOST)

self.run = True
Expand Down Expand Up @@ -75,6 +80,9 @@ def _work(self):
else:
raise Exception('Unhandled error {}', message_type)

if self.liveness_callback is not None:
self.liveness_callback()

self.logger.info('Work loop exited')

def start(self):
Expand Down

0 comments on commit 8d52a32

Please sign in to comment.