Skip to content

Commit cbd0c43

Browse files
HeshamHM28misrasaurabh1Saga4
authored
[Chore] Notify via Email When codeflash --all Completes (#529)
* notify user via email when --all optimizations complete * fix the type error * add todo --------- Co-authored-by: Saurabh Misra <[email protected]> Co-authored-by: Sarthak Agarwal <[email protected]>
1 parent d15203e commit cbd0c43

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

codeflash/api/cfapi.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,3 +261,16 @@ def mark_optimization_success(trace_id: str, *, is_optimization_found: bool) ->
261261
"""
262262
payload = {"trace_id": trace_id, "is_optimization_found": is_optimization_found}
263263
return make_cfapi_request(endpoint="/mark-as-success", method="POST", payload=payload)
264+
265+
266+
def send_completion_email() -> Response:
267+
"""Send an email notification when codeflash --all completes."""
268+
try:
269+
owner, repo = get_repo_owner_and_name()
270+
except Exception as e:
271+
sentry_sdk.capture_exception(e)
272+
response = requests.Response()
273+
response.status_code = 500
274+
return response
275+
payload = {"owner": owner, "repo": repo}
276+
return make_cfapi_request(endpoint="/send-completion-email", method="POST", payload=payload)

codeflash/optimization/optimizer.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from typing import TYPE_CHECKING
1010

1111
from codeflash.api.aiservice import AiServiceClient, LocalAiServiceClient
12+
from codeflash.api.cfapi import send_completion_email
1213
from codeflash.cli_cmds.console import console, logger, progress_bar
1314
from codeflash.code_utils import env_utils
1415
from codeflash.code_utils.code_utils import cleanup_paths, get_run_tmp_file
@@ -342,6 +343,11 @@ def run(self) -> None:
342343
logger.info("❌ No optimizations found.")
343344
elif self.args.all:
344345
logger.info("✨ All functions have been optimized! ✨")
346+
response = send_completion_email() # TODO: Include more details in the email
347+
if response.ok:
348+
logger.info("✅ Completion email sent successfully.")
349+
else:
350+
logger.warning("⚠️ Failed to send completion email. Status")
345351
finally:
346352
if function_optimizer:
347353
function_optimizer.cleanup_generated_files()

0 commit comments

Comments
 (0)