awsimple 4.1.0__py3-none-any.whl → 4.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of awsimple might be problematic. Click here for more details.
- awsimple/__version__.py +1 -1
- awsimple/pubsub.py +21 -6
- {awsimple-4.1.0.dist-info → awsimple-4.2.0.dist-info}/METADATA +1 -1
- {awsimple-4.1.0.dist-info → awsimple-4.2.0.dist-info}/RECORD +8 -8
- {awsimple-4.1.0.dist-info → awsimple-4.2.0.dist-info}/WHEEL +0 -0
- {awsimple-4.1.0.dist-info → awsimple-4.2.0.dist-info}/licenses/LICENSE +0 -0
- {awsimple-4.1.0.dist-info → awsimple-4.2.0.dist-info}/licenses/LICENSE.txt +0 -0
- {awsimple-4.1.0.dist-info → awsimple-4.2.0.dist-info}/top_level.txt +0 -0
awsimple/__version__.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
__application_name__ = "awsimple"
|
|
2
2
|
__title__ = __application_name__
|
|
3
3
|
__author__ = "abel"
|
|
4
|
-
__version__ = "4.
|
|
4
|
+
__version__ = "4.2.0"
|
|
5
5
|
__author_email__ = "j@abel.co"
|
|
6
6
|
__url__ = "https://github.com/jamesabel/awsimple"
|
|
7
7
|
__download_url__ = "https://github.com/jamesabel/awsimple"
|
awsimple/pubsub.py
CHANGED
|
@@ -3,6 +3,7 @@ pub/sub abstraction on top of AWS SNS and SQS using boto3.
|
|
|
3
3
|
"""
|
|
4
4
|
|
|
5
5
|
import time
|
|
6
|
+
from functools import lru_cache
|
|
6
7
|
from typing import Any, Dict, List, Callable, Union
|
|
7
8
|
from datetime import timedelta
|
|
8
9
|
from multiprocessing import Process, Queue, Event
|
|
@@ -119,6 +120,20 @@ class _SubscriptionThread(Thread):
|
|
|
119
120
|
self.new_event.set() # notify parent process that a new message is available
|
|
120
121
|
|
|
121
122
|
|
|
123
|
+
@lru_cache
|
|
124
|
+
def make_name_aws_safe(name: str) -> str:
|
|
125
|
+
"""
|
|
126
|
+
Make a name safe for an SQS queue to subscribe to an SNS topic.
|
|
127
|
+
|
|
128
|
+
:param name: input name
|
|
129
|
+
:return: AWS safe name
|
|
130
|
+
"""
|
|
131
|
+
safe_name = "".join([c for c in name.strip().lower() if c.isalnum()]) # only allow alphanumeric characters
|
|
132
|
+
if len(safe_name) < 1:
|
|
133
|
+
raise ValueError(f'"{name}" is not valid after making AWS safe - result must contain at least one alphanumeric character.')
|
|
134
|
+
return safe_name
|
|
135
|
+
|
|
136
|
+
|
|
122
137
|
class PubSub(Process):
|
|
123
138
|
|
|
124
139
|
@typechecked()
|
|
@@ -136,12 +151,13 @@ class PubSub(Process):
|
|
|
136
151
|
Pub and Sub.
|
|
137
152
|
Create in a separate process to offload from main thread. Also facilitates use of moto mock in tests.
|
|
138
153
|
|
|
139
|
-
:param channel: Channel name (SNS topic name).
|
|
154
|
+
:param channel: Channel name (used for SNS topic name). This must not be a prefix of other channel names to avoid collisions (don't name one channel "a" and another "ab").
|
|
140
155
|
:param node_name: Node name (SQS queue name suffix). Defaults to a combination of computer name and username, but can be passed in for customization and/or testing.
|
|
141
156
|
:param sub_callback: Optional thread and process safe callback function to be called when a new message is received. The function should accept a single argument, which will be the message as a dictionary.
|
|
142
157
|
"""
|
|
143
|
-
|
|
144
|
-
self.
|
|
158
|
+
|
|
159
|
+
self.channel = "ps" + make_name_aws_safe(channel) # prefix with ps (pubsub) to avoid collisions with other uses of SNS topics and SQS queues
|
|
160
|
+
self.node_name = make_name_aws_safe(node_name)
|
|
145
161
|
self.sub_callback = sub_callback
|
|
146
162
|
|
|
147
163
|
self.profile_name = profile_name
|
|
@@ -158,8 +174,7 @@ class PubSub(Process):
|
|
|
158
174
|
|
|
159
175
|
def run(self):
|
|
160
176
|
|
|
161
|
-
|
|
162
|
-
sqs_queue_name = f"{sqs_prefix}{self.node_name}"
|
|
177
|
+
sqs_queue_name = f"{self.channel}{self.node_name}"
|
|
163
178
|
|
|
164
179
|
sns = SNSAccess(
|
|
165
180
|
self.channel,
|
|
@@ -188,7 +203,7 @@ class PubSub(Process):
|
|
|
188
203
|
_connect_sns_to_sqs(sqs, sns)
|
|
189
204
|
|
|
190
205
|
sqs_metadata.update_table_mtime() # update SQS use time (the existing infrastructure calls it a "table", but we're using it for the SQS queue)
|
|
191
|
-
remove_old_queues(
|
|
206
|
+
remove_old_queues(self.channel) # clean up old queues
|
|
192
207
|
|
|
193
208
|
sqs_thread = _SubscriptionThread(sqs, self._new_event)
|
|
194
209
|
sqs_thread.start()
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
awsimple/__init__.py,sha256=RT9hATlcKnnvJYnSh7tCWEeeT2LyleL_vT1Zdz0nSkM,1051
|
|
2
|
-
awsimple/__version__.py,sha256=
|
|
2
|
+
awsimple/__version__.py,sha256=fij2OF6RPCHAUREavC9bv6YK4lD3nxXPz58k91OHyT4,323
|
|
3
3
|
awsimple/aws.py,sha256=NbRu1v_J5j2-pcefNZ5Xggii3mM9nHpeHMz9L9K9r-U,7653
|
|
4
4
|
awsimple/cache.py,sha256=_LvPx76215t8KhAJOin6Pe2b4lWpB6kbKpdzgR4FeA4,7206
|
|
5
5
|
awsimple/dynamodb.py,sha256=7MNxAutOCMTS4JSX-DLOwzaImJ2TzIc7kfQzQPAy5y8,41193
|
|
@@ -8,14 +8,14 @@ awsimple/exceptions.py,sha256=Ew-S8YkHVWrZFI_Yik5n0cJ7Ss4Kig5JsEPQ-9z18SU,922
|
|
|
8
8
|
awsimple/logs.py,sha256=s9FhdDFWjfxGCVDx-FNTPgJ-YN1AOAgz4HNxTVfRARE,4108
|
|
9
9
|
awsimple/mock.py,sha256=eScbnxFF9xAosOAsL-NZgp_P-fezB6StQMkb85Y3TNo,574
|
|
10
10
|
awsimple/platform.py,sha256=TObvLIVgRGh-Mh4ZCxFfxAmrn8KNMHktr6XkDZX8JYE,376
|
|
11
|
-
awsimple/pubsub.py,sha256=
|
|
11
|
+
awsimple/pubsub.py,sha256=Pw5foOHtpd-tAWMRlnSYuRpa4c-fi1tMZfesizn9UDc,10143
|
|
12
12
|
awsimple/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
13
13
|
awsimple/s3.py,sha256=OhWF1uv4oLmBF5jAhKIi918iUQxx4CX8bTEvQ5wLYr8,24050
|
|
14
14
|
awsimple/sns.py,sha256=T_FyN8eSmBPo213HOfB3UBlMrvtBK768IaRo_ks-7do,3526
|
|
15
15
|
awsimple/sqs.py,sha256=9ZY7161CpmYpcxlCFIfW8bvMn9SGl4cgGR79I4MFLDk,17281
|
|
16
|
-
awsimple-4.
|
|
17
|
-
awsimple-4.
|
|
18
|
-
awsimple-4.
|
|
19
|
-
awsimple-4.
|
|
20
|
-
awsimple-4.
|
|
21
|
-
awsimple-4.
|
|
16
|
+
awsimple-4.2.0.dist-info/licenses/LICENSE,sha256=d956YAgtDaxgxQmccyUk__EfhORZyBjvmJ8pq6zYTxk,1093
|
|
17
|
+
awsimple-4.2.0.dist-info/licenses/LICENSE.txt,sha256=d956YAgtDaxgxQmccyUk__EfhORZyBjvmJ8pq6zYTxk,1093
|
|
18
|
+
awsimple-4.2.0.dist-info/METADATA,sha256=TRNowXIo5ZYVRxy37xcGZ4o4UyIikkS1_JcjrqHGnBg,6638
|
|
19
|
+
awsimple-4.2.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
20
|
+
awsimple-4.2.0.dist-info/top_level.txt,sha256=mwqCoH_8vAaK6iYioiRbasXmVCQM7AK3grNWOKp2VHE,9
|
|
21
|
+
awsimple-4.2.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|