Skip to content

Commit d131eb6

Browse files
authored
make default prefix empty, and minor cleanups (#52)
make default prefix empty, and minor readme & test cleanups
1 parent 71fec89 commit d131eb6

File tree

4 files changed

+25
-29
lines changed

4 files changed

+25
-29
lines changed

README.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ echo.delay(message='Hello World!')
3636
```
3737
**NOTE:** This assumes that you have your AWS keys in the appropriate environment variables, or are using IAM roles. Consult the `boto3` [documentation](https://boto3.readthedocs.org/en/latest/) for further info.
3838

39-
If you don't pass a queue name, the `EB_SQS_DEFAULT_QUEUE` setting is used. If not set, the queue name is `default`.
39+
If you don't pass a queue name, the `EB_SQS_DEFAULT_QUEUE` setting is used. If not set, the queue name is `eb-sqs-default`.
4040

4141
Additionally the task decorator supports `max_retries` (default `0`) and `use_pickle` (default `False`) attributes for advanced control task execution.
4242

@@ -98,6 +98,8 @@ This makes the code much simpler, and allows using classes to invoke your method
9898

9999
This is how you would define your class:
100100
```python
101+
from eb_sqs.auto_tasks.service import AutoTaskService
102+
101103
class MyService:
102104
def __init__(self, p1=default1, ..., pN=defaultN, auto_task_service=None):
103105
self._auto_task_service = auto_task_service or AutoTaskService()
@@ -132,14 +134,10 @@ The following settings can be used to fine tune django-eb-sqs. Copy them into yo
132134
- EB_SQS_DEFAULT_DELAY (`0`): Default task delay time in seconds.
133135
- EB_SQS_DEFAULT_MAX_RETRIES (`0`): Default retry limit for all tasks.
134136
- EB_SQS_DEFAULT_COUNT_RETRIES (`True`): Count retry calls. Needed if max retries check shall be executed.
135-
- EB_SQS_DEFAULT_QUEUE (`default`): Default queue name if none is specified when creating a task.
137+
- EB_SQS_DEFAULT_QUEUE (`eb-sqs-default`): Default queue name if none is specified when creating a task.
136138
- EB_SQS_EXECUTE_INLINE (`False`): Execute tasks immediately without using SQS. Useful during development. Global setting `True` will override setting it on a task level.
137139
- EB_SQS_FORCE_SERIALIZATION (`False`): Forces serialization of tasks when executed `inline`. This setting is helpful during development to see if all arguments are serialized and deserialized properly.
138-
- EB_SQS_GROUP_CALLBACK_TASK (`None`): Group callback (String or Function). Must be a valid task.
139-
- EB_SQS_QUEUE_PREFIX (`eb-sqs-`): Prefix to use for the queues. The prefix is added to the queue name.
140-
- EB_SQS_REDIS_CLIENT (`None`): Set the Redis connection client (`StrictRedis`)
141-
- EB_SQS_REDIS_EXPIRY (`604800`): Default expiry time in seconds until a group is removed
142-
- EB_SQS_REDIS_KEY_PREFIX (`eb-sqs-`): Prefix used for all Redis keys
140+
- EB_SQS_QUEUE_PREFIX (``): Prefix to use for the queues. The prefix is added to the queue name.
143141
- EB_SQS_USE_PICKLE (`False`): Enable to use `pickle` to serialize task parameters. Uses `json` as default.
144142
- EB_SQS_AWS_MAX_RETRIES (`30`): Default retry limit on a boto3 call to AWS SQS.
145143
- EB_SQS_REFRESH_PREFIX_QUEUES_S (`10`): Minimal number of seconds to wait between refreshing queue list, in case prefix is used

eb_sqs/settings.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
NO_QUEUES_WAIT_TIME_S = getattr(settings, 'NO_QUEUES_WAIT_TIME_S', 5) # type: int
1010

1111
AUTO_ADD_QUEUE = getattr(settings, 'EB_SQS_AUTO_ADD_QUEUE', False) # type: bool
12-
QUEUE_PREFIX = getattr(settings, 'EB_SQS_QUEUE_PREFIX', 'eb-sqs-') # type: str
13-
DEFAULT_QUEUE = getattr(settings, 'EB_SQS_DEFAULT_QUEUE', 'default') # type: str
12+
QUEUE_PREFIX = getattr(settings, 'EB_SQS_QUEUE_PREFIX', '') # type: str
13+
DEFAULT_QUEUE = getattr(settings, 'EB_SQS_DEFAULT_QUEUE', 'eb-sqs-default') # type: str
1414

1515
EXECUTE_INLINE = getattr(settings, 'EB_SQS_EXECUTE_INLINE', False) # type: bool
1616
FORCE_SERIALIZATION = getattr(settings, 'EB_SQS_FORCE_SERIALIZATION', False) # type: bool
@@ -21,13 +21,6 @@
2121

2222
USE_PICKLE = getattr(settings, 'EB_SQS_USE_PICKLE', False) # type: bool
2323

24-
GROUP_CALLBACK_TASK = getattr(settings, 'EB_SQS_GROUP_CALLBACK_TASK', None) # type: Any
25-
26-
REDIS_CLIENT = getattr(settings, 'EB_SQS_REDIS_CLIENT', None) # type: StrictRedis
27-
# default: 7 days
28-
REDIS_EXPIRY = getattr(settings, 'EB_SQS_REDIS_EXPIRY', 3600 * 24 * 7) # type: int
29-
REDIS_KEY_PREFIX = getattr(settings, 'EB_SQS_REDIS_KEY_PREFIX', 'eb-sqs-') # type: str
30-
3124
WORKER_FACTORY = getattr(settings, 'EB_SQS_WORKER_FACTORY', None) # type: WorkerFactory
3225

3326
DEAD_LETTER_MODE = getattr(settings, 'EB_SQS_DEAD_LETTER_MODE', False) # type: bool

eb_sqs/tests/auto_tasks/tests_auto_tasks.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,31 @@
88

99

1010
class TestService:
11-
_TEST_MOCK = Mock()
12-
_MAX_RETRY_NUM = 5
11+
TEST_MOCK = None
12+
MAX_RETRY_NUM = 5
1313

1414
def __init__(self, auto_task_service=None):
1515
self._auto_task_service = auto_task_service or AutoTaskService()
1616

1717
self._auto_task_service.register_task(self.task_method)
18-
self._auto_task_service.register_task(self.task_retry_method, max_retries=self._MAX_RETRY_NUM)
18+
self._auto_task_service.register_task(self.task_retry_method, max_retries=self.MAX_RETRY_NUM)
1919

2020
self._auto_task_service.register_task(self.task_recursive_method)
2121
self._auto_task_service.register_task(self.task_other_method)
2222

2323
def task_method(self, *args, **kwargs):
24-
self._TEST_MOCK.task_method(*args, **kwargs)
24+
self.TEST_MOCK.task_method(*args, **kwargs)
2525

2626
def task_retry_method(self, *args, **kwargs):
27-
self._TEST_MOCK.task_retry_method(*args, **kwargs)
27+
self.TEST_MOCK.task_retry_method(*args, **kwargs)
2828

2929
def max_retry_fun():
30-
self._TEST_MOCK.task_max_retry_method(*args, **kwargs)
30+
self.TEST_MOCK.task_max_retry_method(*args, **kwargs)
3131

3232
raise RetryableTaskException(Exception('Test'), max_retries_func=max_retry_fun)
3333

3434
def non_task_method(self):
35-
self._TEST_MOCK.non_task_method()
35+
self.TEST_MOCK.non_task_method()
3636

3737
def task_recursive_method(self, tries=2):
3838
if tries > 0:
@@ -41,7 +41,7 @@ def task_recursive_method(self, tries=2):
4141
self.task_other_method()
4242

4343
def task_other_method(self):
44-
self._TEST_MOCK.task_other_method()
44+
self.TEST_MOCK.task_other_method()
4545

4646

4747
class AutoTasksTest(TestCase):
@@ -53,17 +53,19 @@ def setUp(self):
5353

5454
settings.EXECUTE_INLINE = True
5555

56+
TestService.TEST_MOCK = Mock()
57+
5658
def test_task_method(self):
5759
self._test_service.task_method(*self._args, **self._kwargs)
5860

59-
TestService._TEST_MOCK.task_method.assert_called_once_with(*self._args, **self._kwargs)
61+
TestService.TEST_MOCK.task_method.assert_called_once_with(*self._args, **self._kwargs)
6062

6163
def test_task_retry_method(self):
6264
self._test_service.task_retry_method(*self._args, **self._kwargs)
6365

64-
TestService._TEST_MOCK.task_retry_method.assert_has_calls([call(*self._args, **self._kwargs)] * TestService._MAX_RETRY_NUM)
66+
TestService.TEST_MOCK.task_retry_method.assert_has_calls([call(*self._args, **self._kwargs)] * TestService.MAX_RETRY_NUM)
6567

66-
TestService._TEST_MOCK.task_max_retry_method.assert_called_once_with(*self._args, **self._kwargs)
68+
TestService.TEST_MOCK.task_max_retry_method.assert_called_once_with(*self._args, **self._kwargs)
6769

6870
def test_non_task_method(self):
6971
_auto_task_wrapper.delay(
@@ -73,9 +75,9 @@ def test_non_task_method(self):
7375
execute_inline=True
7476
)
7577

76-
TestService._TEST_MOCK.non_task_method.assert_not_called()
78+
TestService.TEST_MOCK.non_task_method.assert_not_called()
7779

7880
def test_task_recursive_method(self):
7981
self._test_service.task_recursive_method()
8082

81-
TestService._TEST_MOCK.task_other_method.assert_called_once_with()
83+
TestService.TEST_MOCK.task_other_method.assert_called_once_with()

eb_sqs/tests/aws/tests_aws_queue_client.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414

1515

1616
class AwsQueueClientTest(TestCase):
17+
def setUp(self):
18+
settings.QUEUE_PREFIX = 'eb-sqs-'
19+
1720
@mock_sqs()
1821
def test_add_message(self):
1922
sqs = boto3.resource('sqs',

0 commit comments

Comments
 (0)