-
Notifications
You must be signed in to change notification settings - Fork 8
⚙️ FEATURE-#281: on_input_change policy for resume workflows #282
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
Merged
Merged
Changes from all commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
6909441
⚙️ FEATURE-#281: Add InputChangedError and InvalidOnInputChange excep…
FernandoCelmer cdf7f67
⚙️ FEATURE-#281: Add Storage.clear(workflow_id) to ABC for bulk check…
FernandoCelmer b163569
⚙️ FEATURE-#281: Implement clear() in StorageDefault
FernandoCelmer 69f26b1
⚙️ FEATURE-#281: Implement clear() in StorageFile
FernandoCelmer 4e29886
⚙️ FEATURE-#281: Add S3.delete_prefix helper for bulk checkpoint dele…
FernandoCelmer dfeca14
⚙️ FEATURE-#281: Implement clear() in StorageS3 via delete_prefix
FernandoCelmer d7cdad7
⚙️ FEATURE-#281: Add fingerprint module with hashing and storage helpers
FernandoCelmer bbc1a55
⚙️ FEATURE-#281: Wire on_input_change policy into Manager
FernandoCelmer 897f463
❤️ TEST-#281: Cover StorageDefault.clear
FernandoCelmer 8cf9758
❤️ TEST-#281: Cover StorageFile.clear
FernandoCelmer 6935499
❤️ TEST-#281: Cover StorageS3.clear and delete_prefix guard
FernandoCelmer 6cee9b0
❤️ TEST-#281: Cover fingerprint helpers
FernandoCelmer 49c09c5
❤️ TEST-#281: Cover on_input_change reuse, reset, raise policies
FernandoCelmer 567c30b
📘 DOCS-#281: Add checkpoint_input_change example
FernandoCelmer 9817fe0
📦 PyPI: Update version to 1.0.0.dev6
actions-user 3353ea2
🪲 BUG-#281: Add __future__ annotations to fix Python 3.9 collection w…
FernandoCelmer 132eba6
📦 PyPI-#281: Add eval_type_backport for Python 3.9 PEP 604 evaluation
FernandoCelmer 2c2535c
📦 PyPI-#281: Regenerate poetry.lock
FernandoCelmer a67f8b0
📝 PEP8-#281: Fix ruff I001 import order on workflow.py and test_finge…
FernandoCelmer 68127ee
🪲 BUG-#281: Drop json.dumps(default=str) so non-serializable inputs r…
FernandoCelmer f1de40d
❤️ TEST-#281: Assert repr fallback is stable across calls
FernandoCelmer 2c0c34e
🪲 BUG-#281: Anchor clear() prefix with hyphen separator across providers
FernandoCelmer 85bf225
❤️ TEST-#281: Cover clear() prefix anchoring in StorageDefault
FernandoCelmer d764f67
⚙️ FEATURE-#281: Add GCS.delete_prefix helper for bulk checkpoint del…
FernandoCelmer 9d4e81d
⚙️ FEATURE-#281: Make Storage.clear abstract so providers must implem…
FernandoCelmer d6374fc
📝 PEP8-#281: Drop quoted TaskBuilder annotation (redundant with __fut…
FernandoCelmer 90b70fc
⚙️ FEATURE-#281: Move VALID_POLICIES into TypeInputChange module unde…
FernandoCelmer 009d158
♻️ REFACTOR-#281: Drop VALID_POLICIES from fingerprint module
FernandoCelmer e06de76
⚙️ FEATURE-#281: Accept explicit fingerprint kwarg overriding payload…
FernandoCelmer da7eec3
❤️ TEST-#281: Cover explicit fingerprint kwarg behavior
FernandoCelmer 5ce5cd7
📘 DOCS-#281: Show explicit fingerprint usage in example
FernandoCelmer 2e69adc
📝 PEP8-#281: Apply ruff format across touched files
FernandoCelmer a56763e
🔗 CHORE-#281: Bump examples submodule
FernandoCelmer 87aa544
🪲 BUG-#282: Resolve merge conflict with develop
FernandoCelmer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
| @@ -1 +1 @@ | ||
| 1.0.0.dev5 | ||
| 1.0.0.dev6 |
This file contains hidden or 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,38 @@ | ||
| from hashlib import sha256 | ||
| from uuid import UUID | ||
|
|
||
| from dotflow import Config, DotFlow, action | ||
| from dotflow.providers import StorageFile | ||
|
|
||
|
|
||
| @action | ||
| def step_one(initial_context): | ||
| return {"loaded": initial_context.storage} | ||
|
|
||
|
|
||
| @action | ||
| def step_two(previous_context): | ||
| return {"transformed": previous_context.storage} | ||
|
|
||
|
|
||
| config = Config(storage=StorageFile()) | ||
|
|
||
|
|
||
| def main(): | ||
| payload = {"s3_key": "uploads/data.zip", "v": 1} | ||
|
|
||
| workflow = DotFlow( | ||
| config=config, | ||
| workflow_id=UUID("12345678-1234-5678-1234-567812345678"), | ||
| ) | ||
|
|
||
| workflow.task.add(step=[step_one, step_two], initial_context=payload) | ||
|
|
||
| fp = sha256(payload["s3_key"].encode()).hexdigest() | ||
| workflow.start(resume=True, on_input_change="reset", fingerprint=fp) | ||
|
|
||
| return workflow | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() |
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| """Flow ABC""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from abc import ABC, abstractmethod | ||
| from uuid import UUID | ||
|
|
||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,45 @@ | ||
| """Input fingerprint helpers for resume + on_input_change policy.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from hashlib import sha256 | ||
| from json import dumps | ||
| from typing import Any | ||
|
|
||
| from dotflow.core.context import Context | ||
|
|
||
| FP_KEY_SUFFIX = "-_input_fp" | ||
|
|
||
|
|
||
| def fingerprint_of(values: list[Any]) -> str: | ||
| """SHA256 of JSON-serialized list of initial_context payloads. | ||
|
|
||
| Inputs must be JSON-serializable (primitives, lists, dicts). | ||
| Non-serializable objects fall back to ``repr``, which is **not** | ||
| guaranteed to be stable across processes — objects without a custom | ||
| ``__repr__`` will produce different fingerprints on every run because | ||
| the default repr embeds the memory address. | ||
| """ | ||
| try: | ||
| encoded = dumps(values, sort_keys=True) | ||
| except (TypeError, ValueError): | ||
|
FernandoCelmer marked this conversation as resolved.
FernandoCelmer marked this conversation as resolved.
|
||
| encoded = repr(values) | ||
|
|
||
| return sha256(encoded.encode("utf-8")).hexdigest() | ||
|
|
||
|
|
||
| def fp_key(workflow_id: str) -> str: | ||
| return f"{workflow_id}{FP_KEY_SUFFIX}" | ||
|
|
||
|
|
||
| def read_fingerprint(storage, workflow_id: str) -> str | None: | ||
| context = storage.get(key=fp_key(workflow_id)) | ||
|
|
||
| if isinstance(context, Context) and isinstance(context.storage, str): | ||
| return context.storage | ||
|
|
||
| return None | ||
|
|
||
|
|
||
| def write_fingerprint(storage, workflow_id: str, value: str) -> None: | ||
| storage.post(key=fp_key(workflow_id), context=Context(storage=value)) | ||
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,15 +1,18 @@ | ||
| """Types __init__ module.""" | ||
|
|
||
| from dotflow.core.types.execution import TypeExecution | ||
| from dotflow.core.types.input_change import VALID_POLICIES, TypeInputChange | ||
| from dotflow.core.types.overlap import TypeOverlap | ||
| from dotflow.core.types.status import TypeStatus | ||
| from dotflow.core.types.storage import TypeStorage | ||
| from dotflow.core.types.workflow import WorkflowStatus | ||
|
|
||
| __all__ = [ | ||
| "TypeExecution", | ||
| "TypeInputChange", | ||
| "TypeOverlap", | ||
| "TypeStatus", | ||
| "TypeStorage", | ||
| "VALID_POLICIES", | ||
| "WorkflowStatus", | ||
| ] |
This file contains hidden or 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,31 @@ | ||
| """Type InputChange policy module.""" | ||
|
|
||
| from typing import Annotated | ||
|
|
||
| from typing_extensions import Doc | ||
|
|
||
|
|
||
| class TypeInputChange: | ||
| """ | ||
| Import: | ||
| You can import the **TypeInputChange** class with: | ||
|
|
||
| from dotflow.core.types import TypeInputChange | ||
| """ | ||
|
|
||
| REUSE: Annotated[ | ||
| str, Doc("Keep prior checkpoints; ignore the new input.") | ||
| ] = "reuse" | ||
| RESET: Annotated[str, Doc("Drop prior checkpoints and start fresh.")] = ( | ||
| "reset" | ||
| ) | ||
| RAISE: Annotated[str, Doc("Refuse to start; raise InputChangedError.")] = ( | ||
| "raise" | ||
| ) | ||
|
|
||
|
|
||
| VALID_POLICIES = ( | ||
| TypeInputChange.REUSE, | ||
| TypeInputChange.RESET, | ||
| TypeInputChange.RAISE, | ||
| ) |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.