-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixing up the library, adding tox tests, adding travis config
- Loading branch information
1 parent
fb2e87b
commit 0ccc430
Showing
17 changed files
with
995 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2019 Jacobi Petrucciani | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[[source]] | ||
url = "https://pypi.python.org/simple" | ||
verify_ssl = true | ||
|
||
[packages] | ||
boto3 = "*" | ||
|
||
[dev-packages] | ||
tox = "*" | ||
moto = "*" | ||
pytest = "*" |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,76 @@ | ||
""" | ||
qoo module | ||
""" | ||
import boto3 | ||
import os | ||
from qoo.errors import FailedToCreateQueue | ||
from qoo.queues import Job, Queue # noqa | ||
from typing import List | ||
|
||
|
||
AWS_DEFAULT_REGION = "us-east-1" | ||
|
||
|
||
def _client(region: str = ""): | ||
"""returns a boto3 sqs client""" | ||
region_name = region or os.environ.get("AWS_DEFAULT_REGION", AWS_DEFAULT_REGION) | ||
return boto3.client("sqs", region_name=region_name) | ||
|
||
|
||
def login( | ||
access_key_id: str, secret_access_key: str, region: str = AWS_DEFAULT_REGION | ||
) -> None: | ||
"""sets environment variables for boto3.""" | ||
os.environ["AWS_ACCESS_KEY_ID"] = access_key_id | ||
os.environ["AWS_SECRET_ACCESS_KEY"] = secret_access_key | ||
os.environ["AWS_DEFAULT_REGION"] = region | ||
|
||
|
||
def get(queue_name: str, **kwargs) -> Queue: | ||
"""gets a qoo Queue object by SQS queue_name""" | ||
return Queue(queue_name, **kwargs) | ||
|
||
|
||
def list(region: str = "", verbose: bool = False) -> List[str]: | ||
""" | ||
list all queues in the default or given region | ||
:note: this will only list up to 1000 queue names | ||
""" | ||
sqs_client = _client(region=region) | ||
return [ | ||
(x if verbose else x.split("/")[-1]) | ||
for x in sqs_client.list_queues()["QueueUrls"] | ||
] | ||
|
||
|
||
def create( | ||
queue_name: str, | ||
region: str = "", | ||
delay_seconds: int = 0, | ||
maximum_message_size: int = 262144, | ||
message_retention_period: int = 345600, | ||
visibility_timeout: int = 30, | ||
fifo: bool = False, | ||
receive_message_wait_time_seconds: int = 0, | ||
**additional_attributes | ||
) -> Queue: | ||
""" | ||
attempt to create an SQS queue and return it | ||
:note: most of the common params are here, but you can pass additional_attributes if needed | ||
""" | ||
sqs_client = _client(region=region) | ||
new_queue_url = sqs_client.create_queue( | ||
QueueName=queue_name, | ||
Attributes=dict( | ||
DelaySeconds=str(delay_seconds), | ||
MaximumMessageSize=str(maximum_message_size), | ||
MessageRetentionPeriod=str(message_retention_period), | ||
ReceiveMessageWaitTimeSeconds=str(receive_message_wait_time_seconds), | ||
VisibilityTimeout=str(visibility_timeout), | ||
FifoQueue=str(fifo).lower(), | ||
**additional_attributes | ||
), | ||
) | ||
if not new_queue_url: | ||
raise FailedToCreateQueue() | ||
return get(new_queue_url["QueueUrl"].split("/")[-1]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.