generated from digitalfortress-dev/git-templates
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from digitalfortress-dev/feat/allow-publish-laz…
…y-message-without-subscribe feat: allow to publish lazy message without subscribe
- Loading branch information
Showing
8 changed files
with
165 additions
and
20 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,19 @@ | ||
from sqs_client.client import SQSClient | ||
|
||
sqs_client = SQSClient() | ||
|
||
|
||
# Subscribe to a SQS | ||
@sqs_client.task( | ||
queue_name="sqs-queue-name", | ||
lazy=True, | ||
wait_time_seconds=0, | ||
visibility_timeout=300, | ||
) | ||
def test_task(message, abc): | ||
print("test_task received message:", message) | ||
print("test_task received abc:", abc) | ||
|
||
|
||
# Publish a message | ||
test_task.trigger("Test message", abc=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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from sqs_client.client import SQSClient | ||
from sqs_client.publisher import Publisher | ||
|
||
sqs_client = SQSClient() | ||
|
||
sqs_client.publish( | ||
queue_name="sqs-queue-name", | ||
message="test message", | ||
) | ||
|
||
# or | ||
|
||
publisher = Publisher( | ||
sqs_client=sqs_client, | ||
queue_name="sqs-queue-name", | ||
) | ||
|
||
publisher.publish("test message") | ||
|
||
# publish lazy mode message | ||
publisher.publish_lazy("test lazy message", abc=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 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,6 +1,6 @@ | ||
[project] | ||
name = "sqs-client" | ||
version = "0.0.4" | ||
version = "0.1.0" | ||
authors = [ | ||
{name="Digital Fortress", email="[email protected]" }, | ||
] | ||
|
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,54 @@ | ||
import json | ||
|
||
|
||
class Publisher: | ||
""" | ||
This class represents a publisher to send messages to an SQS queue | ||
""" | ||
|
||
def __init__( | ||
self, | ||
sqs_client, | ||
queue_name, | ||
delay_seconds=0, | ||
): | ||
""" | ||
Initializes the Publisher class. | ||
Args: | ||
sqs_client: (SQSClient) The SQSClient of task. | ||
queue_name: (string) The name of the SQS queue you want to send and receive messages. | ||
delay_seconds: (integer) The length of time, in seconds, for which to delay a specific message. | ||
Valid values: 0 to 900. Default: 0 | ||
""" | ||
self._sqs_client = sqs_client | ||
self._queue_name = queue_name | ||
self._delay_seconds = delay_seconds | ||
|
||
def publish(self, message): | ||
""" | ||
This function allows you to publish a message to an SQS queue. | ||
Args: | ||
message: (string) The message content to be sent. | ||
""" | ||
self._sqs_client.publish( | ||
queue_name=self._queue_name, | ||
delay_seconds=self._delay_seconds, | ||
message=message, | ||
) | ||
|
||
def publish_lazy(self, *args, **kwargs): | ||
""" | ||
This function allows you to publish a message in lazy mode. | ||
""" | ||
self._sqs_client.publish( | ||
queue_name=self._queue_name, | ||
delay_seconds=self._delay_seconds, | ||
message=json.dumps( | ||
{ | ||
"args": args, | ||
"kwargs": kwargs, | ||
} | ||
), | ||
) |
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