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

Add Flyin Notification #1426

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
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
60 changes: 57 additions & 3 deletions examples/flyin_plugin/flyin_plugin/vscode.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

# %% [markdown]
# ## Usage
# ### Add `@vscode` decorator to task function definition
# ### 1. Add `@vscode` decorator to task function definition

# %%
@task
Expand All @@ -35,7 +35,18 @@ def wf_train():
# ```
# $ kubectl port-forward <pod name> <port>
# ```
# Then, open a browser and navigate to `localhost:<port>`, replacing `<port>` with the port number configured above. You should be presented with the interface shown in the image below.
# Then, open a browser and navigate to `localhost:<port>`, replacing `<port>` with the port number configured above.\
#
# You should be presented with the interface shown in the image below.
#
# Take the flyte cluster sandbox mode and flytesnacks-development domain for example.
#
# Create connection using approach 2.
# ```
# $ kubectl port-forward -n flytesnacks-development pod-name 8080:8080
# ```
# Enter the following URL in the browser: http://localhost:8080
# You will see the code server like the screenshot below.

# ### 3. Interactively debug the task
#
Expand Down Expand Up @@ -160,10 +171,53 @@ def wf_exception():
# ```
# # Include this line if `curl` isn't installed in the image.
# RUN apt-get -y install curl
# Download and extract VSCode.
# # Download and extract VSCode.
# RUN mkdir -p /tmp/code-server
# RUN curl -kfL -o /tmp/code-server/code-server-4.18.0-linux-amd64.tar.gz https://github.com/coder/code-server/releases/download/v4.18.0/code-server-4.18.0-linux-amd64.tar.gz
# RUN tar -xzf /tmp/code-server/code-server-4.18.0-linux-amd64.tar.gz -C /tmp/code-server/
# ENV PATH="/tmp/code-server/code-server-4.18.0-linux-amd64/bin:${PATH}"
# # TODO: download and install extensions
# ```


# %% [markdown]
# ### Send Notifications before VSCode server terminated
#
# You can set up notifications to be sent before the VSCode server is terminated.
#
# In the example, we will sent the noticiation to slack when the VSCode server will be terminated in 60 seconds.
#
# You can switch sengrid_notifier to slack_notifier to send the notification through email.
# %%
from flytekit import Secret, task, workflow
from flytekitplugins.flyin import vscode, VscodeConfig, SendgridNotifier, SendgridConfig, SlackNotifier, SlackConfig

sengrid_notifier = SendgridNotifier(sendgrid_conf=SendgridConfig(
from_email="[email protected]",
to_email="[email protected]",
secret_group="sendgrid-api",
secret_key="token",
))
slack_notifier = SlackNotifier(slack_conf=SlackConfig(
channel="demo",
secret_group="slack-api",
secret_key="token",
))

@task(
secret_requests=[Secret(key="token", group="sendgrid-api"),
Secret(key="token", group="slack-api"), ],
)
@vscode(
config=VscodeConfig(),
max_idle_seconds=80,
warning_seconds_before_termination=60,
notifier=slack_notifier,
)
def t(a: int, b: int) -> int:
return a + b

@workflow
def wf(a: int = 5, b: int = 3) -> int:
out = t(a=a, b=b)
return out
Loading