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

Flyin - vscode resume task #2017

Merged
merged 10 commits into from
Dec 8, 2023
Merged

Conversation

troychiu
Copy link
Member

@troychiu troychiu commented Dec 3, 2023

Tracking issue

flyteorg/flyte#4284

Why are the changes needed?

After users launch VSCode server and fix their failed tasks, they may want to resume the task to see if the workflow works well with modified tasks. In this PR, I provide a way to let users effortlessly resume the task with their updated code.

What changes were proposed in this pull request?

In runtime, vscode decorator will generate a Python script flyin_resume_task.py.

import os
import signal

if __name__ == "__main__":
    print("Terminating server and resuming task.")
    answer = input("This operation will kill the server. All unsaved data will be lost, and you will no longer be able to connect to it. Do you really want to terminate? (Y/N): ").strip().upper()
    if answer == 'Y':
        PID = 15504
        os.kill(PID, signal.SIGTERM)
        print(f"The server has been terminated and the task has been resumed.")
    else:
        print("Operation canceled.")

This script will send a signal to the main process, and the main process will know that it should resume the task.

End-to-end usage

With the following workflow, user can run pyflyte run --remote demo.py wf --a 10 --b 0. Since t1 will return a // b, there will be an exception (devision by zero) and the vscode server will be launched because run_task_first is set to true.
(run_task_first was introduced in this pr #1997. When run_task_first is set to true, the decorator would first run user's task, and only launch vscode server if the task fails)

from flytekit import task, workflow

@task()
@vscode(run_task_first=True)
def t1(a: int, b: int) -> int:
    return a // b

@workflow
def wf(a: int, b: int) -> int:
    out = t1(a=a, b=b)
    return out

With flyin_interactive_entrypoint.py and launch.json, users can debug the task with the original input. For example, they can handle the case of b being equal to 0. (flyin_interactive_entrypoint.py and launch.json were introduced in #2000. They can help users easily debug the task in vscode server.)

from flytekit import task, workflow

@task()
@vscode(run_task_first=True)
def t1(a: int, b: int) -> int:
    if b == 0:
        return 0
    return a // b

@workflow
def wf(a: int, b: int) -> int:
    out = t1(a=a, b=b)
    return out

After debugging is done, users may want to resume the task to see if the workflow works well with the modified task. They can simply enter python flyin_resume_task.py or even simpler, use launch.json, and go to Flyte console to check the result.

Screenshots

截圖 2023-12-03 上午2 45 01 截圖 2023-12-03 上午2 46 42

Check all the applicable boxes

  • I updated the documentation accordingly.
  • All new and existing tests passed.
  • All commits are signed-off.

Copy link

codecov bot commented Dec 3, 2023

Codecov Report

Attention: 22 lines in your changes are missing coverage. Please review.

Comparison is base (be4ca8c) 85.17% compared to head (5d7146d) 85.87%.

Files Patch % Lines
...lyin/flytekitplugins/flyin/vscode_lib/decorator.py 33.33% 22 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2017      +/-   ##
==========================================
+ Coverage   85.17%   85.87%   +0.69%     
==========================================
  Files         272      306      +34     
  Lines       21144    22848    +1704     
  Branches     3466     3466              
==========================================
+ Hits        18010    19620    +1610     
- Misses       2543     2637      +94     
  Partials      591      591              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@troychiu troychiu marked this pull request as ready for review December 3, 2023 10:55
Signed-off-by: troychiu <[email protected]>
Signed-off-by: troychiu <[email protected]>
Signed-off-by: troychiu <[email protected]>
Signed-off-by: troychiu <[email protected]>
Signed-off-by: troychiu <[email protected]>
Signed-off-by: troychiu <[email protected]>
Signed-off-by: troychiu <[email protected]>
Signed-off-by: troychiu <[email protected]>
Signed-off-by: byhsu <[email protected]>
Signed-off-by: byhsu <[email protected]>
@ByronHsu ByronHsu merged commit 1056f25 into flyteorg:master Dec 8, 2023
73 of 74 checks passed
Future-Outlier pushed a commit to Future-Outlier/flytekit that referenced this pull request Dec 12, 2023
* functionality done

Signed-off-by: troychiu <[email protected]>

* remove redundant

Signed-off-by: troychiu <[email protected]>

* remove redundant

Signed-off-by: troychiu <[email protected]>

* add comments

Signed-off-by: troychiu <[email protected]>

* refactor

Signed-off-by: troychiu <[email protected]>

* Trigger Build

Signed-off-by: troychiu <[email protected]>

* fix suggestions

Signed-off-by: troychiu <[email protected]>

* fix tests

Signed-off-by: troychiu <[email protected]>

* empty

Signed-off-by: byhsu <[email protected]>

* lint

Signed-off-by: byhsu <[email protected]>

---------

Signed-off-by: troychiu <[email protected]>
Signed-off-by: byhsu <[email protected]>
Co-authored-by: byhsu <[email protected]>
Signed-off-by: Future Outlier <[email protected]>
RRap0so pushed a commit to RRap0so/flytekit that referenced this pull request Dec 15, 2023
* functionality done

Signed-off-by: troychiu <[email protected]>

* remove redundant

Signed-off-by: troychiu <[email protected]>

* remove redundant

Signed-off-by: troychiu <[email protected]>

* add comments

Signed-off-by: troychiu <[email protected]>

* refactor

Signed-off-by: troychiu <[email protected]>

* Trigger Build

Signed-off-by: troychiu <[email protected]>

* fix suggestions

Signed-off-by: troychiu <[email protected]>

* fix tests

Signed-off-by: troychiu <[email protected]>

* empty

Signed-off-by: byhsu <[email protected]>

* lint

Signed-off-by: byhsu <[email protected]>

---------

Signed-off-by: troychiu <[email protected]>
Signed-off-by: byhsu <[email protected]>
Co-authored-by: byhsu <[email protected]>
Signed-off-by: Rafael Raposo <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants