-
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.
Browse files
Browse the repository at this point in the history
* DAB-1528 feat: add dump_object_to_s3 and load_object_from_s3 to utils * DAB-1528 feat: update version to 0.3.0 * addded is_acceptable_recommendation to recommendations_utils
- Loading branch information
Showing
6 changed files
with
268 additions
and
3 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 |
---|---|---|
@@ -1,7 +1,49 @@ | ||
import pickle | ||
from io import BytesIO | ||
from typing import Any | ||
|
||
from botocore.client import BaseClient | ||
from datadog import initialize | ||
from datadog.api.metrics import Metric | ||
|
||
|
||
def send_datadog_metric(options, *args, **kwargs): | ||
initialize(**options) | ||
Metric.send(*args, **kwargs) | ||
|
||
|
||
def dump_object_to_s3(client: BaseClient, obj: Any, bucket: str, key: str): | ||
""" | ||
Dump an object to S3 | ||
:param client: S3 client | ||
:param obj: Object to dump | ||
:param bucket: S3 bucket | ||
:param key: S3 key | ||
:return: None | ||
""" | ||
buff = BytesIO() | ||
buff.write(pickle.dumps(obj)) | ||
buff.seek(0) | ||
|
||
client.put_object( | ||
Body=buff.read(), | ||
Bucket=bucket, | ||
Key=key, | ||
) | ||
|
||
|
||
def load_object_from_s3(client: BaseClient, bucket: str, key: str) -> Any: | ||
""" | ||
Load an object from S3 | ||
:param client: S3 client | ||
:param bucket: S3 bucket | ||
:param key: S3 key | ||
:return: Loaded object | ||
""" | ||
buff = client.get_object( | ||
Bucket=bucket, | ||
Key=key, | ||
)["Body"].read() | ||
return pickle.loads(buff) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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 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