-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1321 from facebookresearch/lshamis/mrp_script
Add example for scripting with cmd interface
- Loading branch information
Showing
6 changed files
with
62 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,7 @@ | ||
# Example 16: Scripting msetup commands | ||
|
||
All `mrp` commands are available in both CLI and script form. | ||
|
||
In this example we demo a `launch.py` script that runs processes sequentially. | ||
|
||
Running launch.py brings up a `redis` server, runs a command to set `foo=bar`, then runs another command to print the value of `foo`. |
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,5 @@ | ||
import redis | ||
|
||
print("============") | ||
print("foo =", redis.Redis().get("foo")) | ||
print("============") |
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,12 @@ | ||
import mrp | ||
import time | ||
|
||
mrp.import_msetup(".") | ||
|
||
mrp.cmd.up("redis") | ||
time.sleep(0.5) | ||
|
||
mrp.cmd.up("set_foo", wait=True) | ||
mrp.cmd.up("get_foo", attach=True, wait=True) | ||
|
||
mrp.cmd.down("redis", wait=True) |
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,27 @@ | ||
import mrp | ||
|
||
mrp.process( | ||
name="redis", | ||
runtime=mrp.Docker(image="redis"), | ||
) | ||
|
||
mrp.process( | ||
name="set_foo", | ||
runtime=mrp.Conda( | ||
channels=["conda-forge"], | ||
dependencies=["redis-py"], | ||
run_command=["python", "set_foo.py"], | ||
), | ||
) | ||
|
||
mrp.process( | ||
name="get_foo", | ||
runtime=mrp.Conda( | ||
channels=["conda-forge"], | ||
dependencies=["redis-py"], | ||
run_command=["python", "get_foo.py"], | ||
), | ||
) | ||
|
||
if __name__ == "__main__": | ||
mrp.main() |
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 @@ | ||
import redis | ||
|
||
redis.Redis().set("foo", "bar") |
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