QueueFetcher makes dealing with SQS queues in Django easier
Project description
QueueFetcher allows you to deal with Amazon SQS queues in an easier manner in Django.
It provides:
run_queue management task to start the task from cli
QueueFetcher class to do the heavy lifting with the pieces seperated out and testable
Getting started
Install queue-fetcher from pip
Add queue_fetcher to INSTALLED_APPLICATIONS
Add to your settings.py:
TEST_SQS = False
QUEUES = {
'Internal Name': 'Name On Amazon'
}
Now build your tasks in your tasks package:
from queue_fetcher.tasks import QueueFetcher
class SampleQueueTask(QueueFetcher):
queue = 'test'
def process_sample(self, msg):
raise NotImplementedError('This does nothing.. yet')
QueueFetcher expects messages from SQS to contain a list of events, with each event containing a message_type attribute of something like update_transaction.
This is then dispatched to a function prefixed with process_.
Visibility Timeout
Tasks run from Django Queue Fetcher can, when they hit an error, keep thrashing your SQS queues. We recommend you set a visibility_timeout on each task to minimise your costs and any errors you send to your logs:
from queue_fetcher.tasks import QueueFetcher
class MyQueueFetcher(QueueFetcher):
"""Same Queue Fetcher.
"""
queue = 'test'
visibility_timeout = 60 # Tell SQS to give us 60 seconds to process
def process_my_message(self, msg):
"""Process a message.
"""
return True
Testing your Code
The queue-fetcher app includes a QueueTestCase class that removes the need to handle SQS in your test code. To use it, simple extend the class and use get_yaml or get_json to get your fixtures, located in the same app as your test.
from queue_fetcher.test import QueueTestCase
from .tasks import ExampleTaskClass
class ExampleTestCase(QueueTestCase):
"""
"""
def test_my_app(self):
"""
"""
fixture = self.get_json('exampleapp/test.sqs.json')
task = ExampleTaskClass()
task.read(fixture)
# Insert your assertions here
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file queue-fetcher-2.0.3.tar.gz.
File metadata
- Download URL: queue-fetcher-2.0.3.tar.gz
- Upload date:
- Size: 6.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0c819426a698d3e76d59cb454bcd383a7db24f72e9785652872627835ad115e7
|
|
| MD5 |
e2ab2f2ff8f6f855ff0855fd927d6018
|
|
| BLAKE2b-256 |
c47d1444dfeac956d9a749c7b0ef2649c312eb63a049d91b56c74d2376ed8518
|
File details
Details for the file queue_fetcher-2.0.3-py2.py3-none-any.whl.
File metadata
- Download URL: queue_fetcher-2.0.3-py2.py3-none-any.whl
- Upload date:
- Size: 10.2 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b9e31f4726f91ec4ed5aa55e12e19812cac0b9b7e476be52f8f8a0273cc302de
|
|
| MD5 |
fb4aae8db60dbadefe113daa7baf1095
|
|
| BLAKE2b-256 |
4c727e4946929912ceba2c00c38badf5d249a376e6c956c3b05d4138792a2d5a
|