This repository has been archived by the owner on Oct 25, 2024. It is now read-only.
generated from arcalot/arcaflow-plugin-template-python
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Attempt at making early exit work * Handle the case where it doesn't respond to the signal * Changed output messages, and fixed linter errors * Get SIGTERM early termination working in some cases * Fix linting errors This version still does not work well for early cancellation * Update to signals for cancellation * Fix linting errors * Update to newest signals api * Fix linting error * Update SDK * Update SDK * Update SDK * Update SDK * Update SDK * Update SDK * Update SDK * Update SDK * Update SDK * Change module name * Temporarily disable signal setting for debugging * Update SDK * Update SDK * Update SDK * Re-enabled exit event, and added missing cancelled_early output * Fix linting * Add git to dockerfile to work with dev version of SDK * Fix git install * Fix file name reference in Dockerfile * Update to release of python SDK * Remove git install No longer needed due to the required dependency being on pypi * Automatic upate of README.md by arcaflow-docsgen arcabot --------- Co-authored-by: arcabot <[email protected]>
- Loading branch information
1 parent
d4c1a5e
commit 20ab1d1
Showing
8 changed files
with
177 additions
and
90 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
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,103 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import sys | ||
import time | ||
import typing | ||
from dataclasses import dataclass, field | ||
from threading import Event | ||
|
||
from arcaflow_plugin_sdk import plugin, validation, predefined_schemas | ||
|
||
|
||
@dataclass | ||
class InputParams: | ||
seconds: typing.Annotated[float, validation.min(0.0)] = field( | ||
metadata={ | ||
"id": "seconds", | ||
"name": "seconds", | ||
"description": "number of seconds to wait as a floating point " | ||
"number for subsecond precision." | ||
} | ||
) | ||
|
||
|
||
@dataclass | ||
class SuccessOutput: | ||
""" | ||
This is the output data structure for the success case. | ||
""" | ||
message: str | ||
actual_wait_seconds: float | ||
|
||
|
||
@dataclass | ||
class ErrorOutput: | ||
""" | ||
This is the output data structure in the error case. | ||
""" | ||
error: str | ||
actual_wait_seconds: float | ||
|
||
|
||
class WaitStep: | ||
exit = Event() | ||
finished_early = False | ||
|
||
@plugin.signal_handler( | ||
id=predefined_schemas.cancel_signal_schema.id, | ||
name=predefined_schemas.cancel_signal_schema.display.name, | ||
description=predefined_schemas.cancel_signal_schema.display. | ||
description, | ||
icon=predefined_schemas.cancel_signal_schema.display.icon, | ||
) | ||
def cancel_step(self, _input: predefined_schemas.cancelInput): | ||
# First, let it know that this is the reason it's exiting. | ||
self.finished_early = True | ||
# Now signal to exit. | ||
self.exit.set() | ||
|
||
@plugin.step_with_signals( | ||
id="wait", | ||
name="Wait", | ||
description="Waits for the given amount of time", | ||
outputs={ | ||
"success": SuccessOutput, | ||
"error": ErrorOutput, | ||
"cancelled_early": ErrorOutput | ||
}, | ||
signal_handler_method_names=["cancel_step"], | ||
signal_emitters=[], | ||
step_object_constructor=lambda: WaitStep(), | ||
) | ||
def wait( | ||
self, | ||
params: InputParams, | ||
) -> typing.Tuple[str, typing.Union[SuccessOutput, ErrorOutput]]: | ||
""" | ||
:param params: | ||
:return: the string identifying which output it is, | ||
as well the output structure | ||
""" | ||
start_time = time.time() | ||
self.exit.wait(params.seconds) | ||
if self.finished_early: | ||
actual_time = time.time() - start_time | ||
return "cancelled_early", ErrorOutput( | ||
"Aborted {:0.2f} seconds after being scheduled to wait for {}" | ||
" seconds.".format(actual_time, params.seconds), | ||
actual_time | ||
) | ||
else: | ||
actual_time = time.time() - start_time | ||
return "success", SuccessOutput( | ||
"Waited {:0.2f} seconds after being scheduled to wait for {}" | ||
" seconds.".format(actual_time, params.seconds), | ||
actual_time | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
sys.exit(plugin.run(plugin.build_schema( | ||
WaitStep.wait, | ||
))) |
This file was deleted.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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