-
Notifications
You must be signed in to change notification settings - Fork 0
Documentation migration #66
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
2 commits
Select commit
Hold shift + click to select a range
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
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,32 @@ | ||
| Concepts | ||
| ======== | ||
|
|
||
| Pipeline | ||
| -------- | ||
|
|
||
| A watergrid application is composed of a single pipeline, There are two types of pipelines: | ||
| - `StandalonePipeline` - For low impact use cases where simplicity is preferred. | ||
| - `HAPipeline` - For use cases where high availability is required along with only-once processing. | ||
|
|
||
| Steps | ||
| ----- | ||
|
|
||
| A pipeline is composed of one or more steps. Once you create a pipeline, you can add steps using the `add_step()` method. | ||
| Watergrid expects that you create a new class for each step that you want to perform in the pipeline. All steps must | ||
| inherit from the abstract `Step` class. Your steps should provide an override for the `run(context)` method. Inside this | ||
| method you can perform any actions you want. | ||
|
|
||
| Context | ||
| ------- | ||
|
|
||
| The context is a key-value store that is passed to each step in the pipeline. You can use the context to store | ||
| data created in your step, and to access data created in previous steps. Changing the `OutputMode` of the context | ||
| in a set allows for splitting or filtering the context after the step completes. This can be used to have subsequent | ||
| steps run multiple times based on the output of the current step. | ||
|
|
||
| Locks | ||
| ----- | ||
|
|
||
| When using the `HAPipeline` class, you must provide a lock to prevent multiple instances from running the same pipeline | ||
| at the same time. The `RedisLock` class is provided by watergrid, but you are free to implement your own lock | ||
| using the `Lock` abstract class. |
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 |
|---|---|---|
| @@ -1,7 +1,42 @@ | ||
| HAPipeline | ||
| ================== | ||
|
|
||
| .. autoclass:: watergrid.pipelines.HAPipeline | ||
| :members: | ||
| :undoc-members: | ||
| :inherited-members: | ||
| In HA mode, you can have several servers running on separate machines. Only | ||
| one server will be able to run the pipeline at a time. If a machine fails, another will take over. | ||
|
|
||
| Steps | ||
| ----- | ||
|
|
||
| 1. Install WaterGrid-Python `pip install watergrid==1.0.1` | ||
| 2. Install Redis (or use the `PipelineLock` class to create your own global mutex). | ||
| 3. Create a pipeline and run it. | ||
|
|
||
| .. code-block:: python | ||
|
|
||
| from watergrid.pipelines import HAPipeline | ||
| from watergrid.steps import Step | ||
| from watergrid.context import DataContext | ||
| from watergrid.locks import RedisPipelineLock | ||
|
|
||
| class SampleStep(Step): | ||
| def __init__(self): | ||
| super().__init__(self.__class__.__name__) | ||
|
|
||
| def run(self, context: DataContext): | ||
| print("Hello World!") | ||
|
|
||
| def main(): | ||
| pipeline_name = "sample_pipeline" | ||
| redis_lock = RedisPipelineLock() | ||
| # Call redis_lock.set_XXXX to configure connection properties if needed. | ||
| redis_lock.connect() # Required by RedisPipelineLock, does not apply to all locks. | ||
| pipeline = HAPipeline(pipeline_name, redis_lock) | ||
| pipeline.add_step(SampleStep()) | ||
| while True: | ||
| pipeline.run() | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| main() | ||
|
|
||
| If Redis is not running on localhost on port 6379, you can call `redis_lock.set_XXXX()` to set those values accordingly. |
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,7 +1,35 @@ | ||
| StandalonePipeline | ||
| ================== | ||
|
|
||
| .. autoclass:: watergrid.pipelines.StandalonePipeline | ||
| :members: | ||
| :undoc-members: | ||
| :inherited-members: | ||
| In standalone mode, only one instance of your application is required. This mode is the easiest to set up, | ||
| but does not provide any fault tolerance or host failover. If you are just getting started, this is the pipeline | ||
| mode to start with. | ||
|
|
||
| Steps | ||
| ----- | ||
|
|
||
| 1. Install WaterGrid-Python `pip install watergrid--1.0.1` | ||
| 2. Create a pipeline and run it. | ||
|
|
||
| .. code-block:: python | ||
|
|
||
| from watergrid.pipelines import StandalonePipeline | ||
| from watergrid.steps import Step | ||
| from watergrid.context import DataContext | ||
|
|
||
| class SampleStep(Step): | ||
| def __init__(self): | ||
| super().__init__(self.__class__.__name__) | ||
|
|
||
| def run(self, context: DataContext): | ||
| print("Hello World!") | ||
|
|
||
| def main(): | ||
| pipeline = StandalonePipeline('sample_pipeline') | ||
| pipeline.add_step(SampleStep()) | ||
| while True: | ||
| pipeline.run() | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| main() |
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.