Skip to content
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

Feat/add batch emails #9296

Merged
merged 36 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
a0ba583
ADD new enums for notification frequency
IonesioJunior Sep 16, 2024
43e9a2e
Update notifier to support batch notifications
IonesioJunior Sep 16, 2024
4808ef1
Add new email_notification_dispatcher thread in server.py
IonesioJunior Sep 16, 2024
11fc225
Update protocol version
IonesioJunior Sep 16, 2024
e72d262
ADD new logic for dispatch notification
IonesioJunior Sep 16, 2024
3336134
Merge branch 'dev' into feat/add_batch_emails
IonesioJunior Sep 17, 2024
1526ac9
Remove non-default value for batched notifications
IonesioJunior Sep 17, 2024
2404437
Undo modified protocol_version.json
IonesioJunior Sep 17, 2024
ff444ed
ADD new changed protocol_version.json
IonesioJunior Sep 17, 2024
a27607b
Add email queue iteration
IonesioJunior Sep 18, 2024
8fc9d91
Update email templates
IonesioJunior Sep 18, 2024
729f27d
Update EmailNotifier to apply email.send_batches
IonesioJunior Sep 18, 2024
3e4d868
Merge branch 'dev' into feat/add_batch_emails
IonesioJunior Sep 18, 2024
c600ad3
Merge branch 'dev' into feat/add_batch_emails
IonesioJunior Sep 19, 2024
1f911af
Merge branch 'dev' into feat/add_batch_emails
IonesioJunior Sep 19, 2024
ad001a2
Fix Request Batch email template
IonesioJunior Sep 19, 2024
4b0f7d2
Merge branch 'dev' into feat/add_batch_emails
IonesioJunior Sep 20, 2024
cf6d926
Update protocol_version with new Object Versions/hashed
IonesioJunior Sep 20, 2024
d861ece
Add new settings.batch_notifications endpoint
IonesioJunior Sep 20, 2024
a7ffbdc
Add internal set_batch_notifications and aux is_time_to_dispatch method
IonesioJunior Sep 20, 2024
abd5d5d
Create new EmailFrequency Object / Adjust NotifierSettings attributes
IonesioJunior Sep 20, 2024
198731f
Add logic to check if it's time to dispatch a new batch email
IonesioJunior Sep 20, 2024
fd2446b
ADD migration functions
IonesioJunior Sep 20, 2024
e686037
Remove unused print statements
IonesioJunior Sep 20, 2024
96a5de6
Merge branch 'dev' into feat/add_batch_emails
IonesioJunior Sep 23, 2024
2f9b2a9
Remove unecessary print statement
IonesioJunior Sep 23, 2024
f88c6e6
Fix small bug when passing NOTIFICATION_FREQUENCY.INSTANT without sta…
IonesioJunior Sep 23, 2024
f112c1e
ADD new batch notification notebook test in /scenarios/bq
IonesioJunior Sep 23, 2024
db88d8c
Fix lint
IonesioJunior Sep 23, 2024
14352e0
Rename notebook test
IonesioJunior Sep 23, 2024
9146f7a
Merge branch 'dev' into feat/add_batch_emails
IonesioJunior Sep 24, 2024
2cd0cad
ADD integration test for batching notifications
IonesioJunior Sep 24, 2024
7f1ed88
Use UTC timezone as server timezone to send notifications
IonesioJunior Sep 24, 2024
cb0fef7
Remove test duplicate
IonesioJunior Sep 24, 2024
fe7f20d
Add pytest-asyncio dep in integration.k8s too
IonesioJunior Sep 24, 2024
6c93864
Merge branch 'dev' into feat/add_batch_emails
IonesioJunior Sep 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
377 changes: 377 additions & 0 deletions notebooks/scenarios/bigquery/060-batch-job-request-notifications.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,377 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "0",
"metadata": {},
"outputs": [],
"source": [
"# stdlib\n",
"import os\n",
"from os import environ as env\n",
"from time import sleep\n",
"\n",
"# syft absolute\n",
"import syft as sy\n",
"from syft.util.test_helpers.email_helpers import SENDER\n",
"from syft.util.test_helpers.email_helpers import get_email_server"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1",
"metadata": {},
"outputs": [],
"source": [
"ADMIN_EMAIL, ADMIN_PW = \"[email protected]\", \"bqpw\"\n",
"\n",
"environment = os.environ.get(\"ORCHESTRA_DEPLOYMENT_TYPE\", \"python\")\n",
"environment"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2",
"metadata": {},
"outputs": [],
"source": [
"# in case we are not in k8s we set them here for orchestra to use\n",
"env[\"DEFAULT_ROOT_EMAIL\"] = ADMIN_EMAIL\n",
"env[\"DEFAULT_ROOT_PASSWORD\"] = ADMIN_PW"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3",
"metadata": {},
"outputs": [],
"source": [
"server = sy.orchestra.launch(\n",
" name=\"bigquery-high\",\n",
" dev_mode=True,\n",
" server_side_type=\"high\",\n",
" reset=True,\n",
" port=\"8080\",\n",
" n_consumers=1, # How many workers to be spawned\n",
" create_producer=True, # Can produce more workers\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4",
"metadata": {},
"outputs": [],
"source": [
"email_server, smtp_server = get_email_server()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5",
"metadata": {},
"outputs": [],
"source": [
"high_client = sy.login(\n",
" url=\"http://localhost:8080\", email=ADMIN_EMAIL, password=ADMIN_PW\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6",
"metadata": {},
"outputs": [],
"source": [
"high_client.api.services.settings.enable_notifications(\n",
" email_sender=SENDER,\n",
" email_server=\"localhost\",\n",
" email_port=\"9025\",\n",
")"
]
},
{
"cell_type": "markdown",
"id": "7",
"metadata": {},
"source": [
"# Check default email instant deliver"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8",
"metadata": {},
"outputs": [],
"source": [
"@sy.syft_function_single_use()\n",
"def test_syft_function(): # noqa: F811\n",
" print(\"Testing syft function request email notification\")\n",
" return True\n",
"\n",
"\n",
"# Create a project\n",
"project = sy.Project(\n",
" name=\"My Cool Project\",\n",
" description=\"\"\"Hi, I want to calculate the mean of your private data,\\\n",
" pretty please!\"\"\",\n",
" members=[high_client],\n",
")\n",
"project.create_code_request(test_syft_function, high_client)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9",
"metadata": {},
"outputs": [],
"source": [
"assert (\n",
" \"A new request has been submitted and requires your attention.\"\n",
" in email_server.load_emails()[ADMIN_EMAIL][-1].email_content\n",
")"
]
},
{
"cell_type": "markdown",
"id": "10",
"metadata": {},
"source": [
"## Batch Notifications"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "11",
"metadata": {},
"outputs": [],
"source": [
"current_admin_email_cache_len = len(email_server.load_emails()[ADMIN_EMAIL])"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "12",
"metadata": {},
"outputs": [],
"source": [
"# syft absolute\n",
"from syft.service.notifier.notifier_enums import EMAIL_TYPES\n",
"from syft.service.notifier.notifier_enums import NOTIFICATION_FREQUENCY\n",
"\n",
"high_client.settings.batch_notifications(\n",
" EMAIL_TYPES.REQUEST_EMAIL, NOTIFICATION_FREQUENCY.DAILY, start_time=\"6:00 pm\"\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "13",
"metadata": {},
"outputs": [],
"source": [
"@sy.syft_function_single_use()\n",
"def test_syft_function_data_upload(): # noqa: F811\n",
" print(\"Testing data upload request notification email\")\n",
" return True\n",
"\n",
"\n",
"project.create_code_request(test_syft_function_data_upload, high_client)\n",
"\n",
"\n",
"@sy.syft_function_single_use()\n",
"def test_syft_function_model_training(): # noqa: F811\n",
" print(\"Testing model training request notification email\")\n",
" return True\n",
"\n",
"\n",
"project.create_code_request(test_syft_function_model_training, high_client)\n",
"\n",
"\n",
"@sy.syft_function_single_use()\n",
"def test_syft_function_data_analysis(): # noqa: F811\n",
" print(\"Testing data analysis request notification email\")\n",
" return True\n",
"\n",
"\n",
"project.create_code_request(test_syft_function_data_analysis, high_client)\n",
"\n",
"\n",
"@sy.syft_function_single_use()\n",
"def test_syft_function_data_cleaning(): # noqa: F811\n",
" print(\"Testing data cleaning request notification email\")\n",
" return True\n",
"\n",
"\n",
"project.create_code_request(test_syft_function_data_cleaning, high_client)\n",
"\n",
"\n",
"@sy.syft_function_single_use()\n",
"def test_syft_function_report_generation(): # noqa: F811\n",
" print(\"Testing report generation request notification email\")\n",
" return True\n",
"\n",
"\n",
"project.create_code_request(test_syft_function_report_generation, high_client)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "14",
"metadata": {},
"outputs": [],
"source": [
"assert current_admin_email_cache_len == len(email_server.load_emails()[ADMIN_EMAIL])"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "15",
"metadata": {},
"outputs": [],
"source": [
"high_client.settings.batch_notifications(\n",
" EMAIL_TYPES.REQUEST_EMAIL, NOTIFICATION_FREQUENCY.INSTANT\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "16",
"metadata": {},
"outputs": [],
"source": [
"sleep(15)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "17",
"metadata": {},
"outputs": [],
"source": [
"assert current_admin_email_cache_len + 1 == len(email_server.load_emails()[ADMIN_EMAIL])"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "18",
"metadata": {},
"outputs": [],
"source": [
"assert (\n",
" \"Batched Requests Notification\"\n",
" in email_server.load_emails()[ADMIN_EMAIL][-1].email_content\n",
")"
]
},
{
"cell_type": "markdown",
"id": "19",
"metadata": {},
"source": [
"## Test Setting batch notifications without passing start time"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "20",
"metadata": {},
"outputs": [],
"source": [
"with sy.raises(sy.SyftException, show=True):\n",
" high_client.settings.batch_notifications(\n",
" EMAIL_TYPES.REQUEST_EMAIL, NOTIFICATION_FREQUENCY.DAILY\n",
" )"
]
},
{
"cell_type": "markdown",
"id": "21",
"metadata": {},
"source": [
"## Test setting batch notifications with bad formatted start time"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "22",
"metadata": {},
"outputs": [],
"source": [
"with sy.raises(sy.SyftException, show=True):\n",
" high_client.settings.batch_notifications(\n",
" EMAIL_TYPES.REQUEST_EMAIL, NOTIFICATION_FREQUENCY.DAILY, \"6 pm\"\n",
" )"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "23",
"metadata": {},
"outputs": [],
"source": [
"smtp_server.stop()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "24",
"metadata": {},
"outputs": [],
"source": [
"server.land()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "25",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.5"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
14 changes: 14 additions & 0 deletions packages/syft/src/syft/protocol/protocol_version.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,20 @@
"hash": "2e1365c5535fa51c22eef79f67dd6444789bc829c27881367e3050e06e2ffbfe",
"action": "remove"
}
},
"NotifierSettings": {
"3": {
"version": 3,
"hash": "226c3e0d4de4368ea9eac6689427cfc27860cf51696741b8dda14f939f3d4fbe",
"action": "add"
}
},
"EmailFrequency": {
"1": {
"version": 1,
"hash": "7659117222a461a959eac7aa1aaf280033c2ca4f1029f97e76051e0474e56759",
"action": "add"
}
}
}
}
Expand Down
Loading
Loading