generated from AgnostiqHQ/covalent-executor-template
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* generalize ssh connect with retry * move exec script to file * update changelog * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * add missing `RuntimeError`; add default err message * set exit_stats=0 on mock func * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * add codecov.yml to ignore exec.py * use class attrs for max attempts and wait time * actually use `self.retry_connect` flag * rename method * add connection retry attempts test * functional test for failing workflow * fix functional test fail in *ssh* electron * using async tmpfile * add failed task handling test * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * comments to clarify new test * more comments and clarification * remove class attrs, add init args * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * add comment --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
10f867e
commit 6a8d8d7
Showing
6 changed files
with
280 additions
and
70 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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
ignore: | ||
# This script is read into a string and formatted. Never executed directly. | ||
- covalent_ssh_plugin/exec.py |
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
""" | ||
Load task `fn` from pickle. Run it. Save the result. | ||
""" | ||
import os | ||
import sys | ||
from pathlib import Path | ||
|
||
result = None | ||
exception = None | ||
|
||
# NOTE: Paths must be substituted-in here by the executor. | ||
remote_result_file = Path("{remote_result_file}").resolve() | ||
remote_function_file = Path("{remote_function_file}").resolve() | ||
current_remote_workdir = Path("{current_remote_workdir}").resolve() | ||
|
||
try: | ||
# Make sure cloudpickle is available. | ||
import cloudpickle as pickle | ||
except Exception as e: | ||
import pickle | ||
|
||
with open(remote_result_file, "wb") as f_out: | ||
pickle.dump((None, e), f_out) | ||
sys.exit(1) # Error. | ||
|
||
current_dir = os.getcwd() | ||
|
||
# Read the function object and arguments from pickle file. | ||
with open(remote_function_file, "rb") as f_in: | ||
fn, args, kwargs = pickle.load(f_in) | ||
|
||
try: | ||
# Execute the task `fn` inside the remote workdir. | ||
current_remote_workdir.mkdir(parents=True, exist_ok=True) | ||
os.chdir(current_remote_workdir) | ||
|
||
result = fn(*args, **kwargs) | ||
|
||
except Exception as e: | ||
exception = e | ||
finally: | ||
os.chdir(current_dir) | ||
|
||
# Save the result to pickle file. | ||
with open(remote_result_file, "wb") as f_out: | ||
pickle.dump((result, exception), f_out) |
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
Oops, something went wrong.