forked from ray-project/ray
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[data] Add ExecutionCallback interface (ray-project#49205)
## Why are these changes needed? Add an ExecutionCallback interface to allow hooking custom callback logic into certain execution events. This can be useful for optimization rules. --------- Signed-off-by: Hao Chen <chenh1024@gmail.com> Signed-off-by: ujjawal-khare <ujjawal.khare@dream11.com>
- Loading branch information
1 parent
366e0ec
commit 87e6665
Showing
3 changed files
with
107 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from typing import List | ||
|
||
from ray.data.context import DataContext | ||
|
||
EXECUTION_CALLBACKS_CONFIG_KEY = "execution_callbacks" | ||
|
||
|
||
class ExecutionCallback: | ||
"""Callback interface for execution events.""" | ||
|
||
def before_execution_starts(self): | ||
"""Called before the Dataset execution starts.""" | ||
... | ||
|
||
def after_execution_succeeds(self): | ||
"""Called after the Dataset execution succeeds.""" | ||
... | ||
|
||
def after_execution_fails(self, error: Exception): | ||
"""Called after the Dataset execution fails.""" | ||
... | ||
|
||
|
||
def get_execution_callbacks(context: DataContext) -> List[ExecutionCallback]: | ||
"""Get all ExecutionCallbacks from the DataContext.""" | ||
return context.get_config(EXECUTION_CALLBACKS_CONFIG_KEY, []) | ||
|
||
|
||
def add_execution_callback(callback: ExecutionCallback, context: DataContext): | ||
"""Add an ExecutionCallback to the DataContext.""" | ||
execution_callbacks = context.get_config(EXECUTION_CALLBACKS_CONFIG_KEY, []) | ||
execution_callbacks.append(callback) | ||
context.set_config(EXECUTION_CALLBACKS_CONFIG_KEY, execution_callbacks) | ||
|
||
|
||
def remove_execution_callback(callback: ExecutionCallback, context: DataContext): | ||
"""Remove an ExecutionCallback from the DataContext.""" | ||
execution_callbacks = context.get_config(EXECUTION_CALLBACKS_CONFIG_KEY, []) | ||
execution_callbacks.remove(callback) | ||
context.set_config(EXECUTION_CALLBACKS_CONFIG_KEY, execution_callbacks) |
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