-
Notifications
You must be signed in to change notification settings - Fork 1
Sync sqs client #160
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Sync sqs client #160
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
ccbc6b0
added sync sqs client
felipao-mx 49f2485
move async clients to agave/tools/asyncio package
felipao-mx 88d6593
add deprecated to some fixtures
felipao-mx 42cd603
update deps
felipao-mx be01401
version
felipao-mx 7c9851c
fix imports
felipao-mx af97d63
fix imports
felipao-mx bb3de88
fix
felipao-mx b26cae2
remove unnecesary session
felipao-mx f4f6b15
version
felipao-mx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Empty file.
Empty file.
This file contains hidden or 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,27 @@ | ||
| import asyncio | ||
| from dataclasses import dataclass | ||
| from typing import Iterable, Optional | ||
|
|
||
| from ..celery import build_celery_message | ||
| from .sqs_client import SqsClient | ||
|
|
||
|
|
||
| @dataclass | ||
| class SqsCeleryClient(SqsClient): | ||
| async def send_task( | ||
| self, | ||
| name: str, | ||
| args: Optional[Iterable] = None, | ||
| kwargs: Optional[dict] = None, | ||
| ) -> None: | ||
| celery_message = build_celery_message(name, args or (), kwargs or {}) | ||
| await super().send_message(celery_message) | ||
|
|
||
| def send_background_task( | ||
| self, | ||
| name: str, | ||
| args: Optional[Iterable] = None, | ||
| kwargs: Optional[dict] = None, | ||
| ) -> asyncio.Task: | ||
| celery_message = build_celery_message(name, args or (), kwargs or {}) | ||
| return super().send_message_async(celery_message) |
This file contains hidden or 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 hidden or 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
Empty file.
This file contains hidden or 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,17 @@ | ||
| from dataclasses import dataclass | ||
| from typing import Iterable, Optional | ||
|
|
||
| from ..celery import build_celery_message | ||
| from .sqs_client import SqsClient | ||
|
|
||
|
|
||
| @dataclass | ||
| class SqsCeleryClient(SqsClient): | ||
| def send_task( | ||
| self, | ||
| name: str, | ||
| args: Optional[Iterable] = None, | ||
| kwargs: Optional[dict] = None, | ||
| ) -> None: | ||
| celery_message = build_celery_message(name, args or (), kwargs or {}) | ||
| self.send_message(celery_message) |
This file contains hidden or 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,34 @@ | ||
| import json | ||
| from dataclasses import dataclass, field | ||
| from typing import Optional, Union | ||
| from uuid import uuid4 | ||
|
|
||
| try: | ||
| import boto3 | ||
| from types_boto3_sqs import SQSClient as Boto3SQSClient | ||
| except ImportError: | ||
| raise ImportError( | ||
| "You must install agave with [sync_aws_tools] option.\n" | ||
| "You can install it with: pip install agave[sync_aws_tools]" | ||
| ) | ||
|
|
||
|
|
||
| @dataclass | ||
| class SqsClient: | ||
| queue_url: str | ||
| region_name: str | ||
| _sqs: Boto3SQSClient = field(init=False) | ||
|
|
||
| def __post_init__(self) -> None: | ||
| self._sqs = boto3.client('sqs', region_name=self.region_name) | ||
|
|
||
| def send_message( | ||
| self, | ||
| data: Union[str, dict], | ||
| message_group_id: Optional[str] = None, | ||
| ) -> None: | ||
| self._sqs.send_message( | ||
| QueueUrl=self.queue_url, | ||
| MessageBody=data if isinstance(data, str) else json.dumps(data), | ||
| MessageGroupId=message_group_id or str(uuid4()), | ||
| ) | ||
This file contains hidden or 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 +1 @@ | ||
| __version__ = '1.1.0' | ||
| __version__ = '1.2.0' |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.