Skip to content

Commit

Permalink
chore: update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
pwwang committed Dec 20, 2023
1 parent 30f892a commit 2a6ee82
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions examples/input_data_callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,6 @@ class MyPipeline(Pipen):
data = [prepare_input_data()]
forks = 3


if __name__ == "__main__":
MyPipeline().run()
1 change: 1 addition & 0 deletions examples/mako-templating.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from pipen.template import Template
from pipen import Proc, Pipen


class TemplateMako(Template):

name = "mako"
Expand Down
2 changes: 2 additions & 0 deletions examples/multijobs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""An example for a process to have multiple jobs and run jobs in parallel"""
from pipen import Proc, Pipen


class MultiJobProc(Proc):
"""A process with multiple jobs"""
input = "i"
Expand All @@ -12,5 +13,6 @@ class MultiJobProc(Proc):
# Let the job takes long the see the parallelization from the progressbar
script = "sleep 1; echo {{in.i}} > {{out.outfile}}"


if __name__ == "__main__":
Pipen().set_starts(MultiJobProc).run()
3 changes: 3 additions & 0 deletions examples/plugin-example.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

logger = get_logger("notify", "info")


class NotifyPlugin:
version = "0.0.0"

Expand All @@ -28,8 +29,10 @@ async def on_proc_start(proc):
async def on_proc_done(proc, succeeded):
logger.info("Calling on_proc_done, succeeded = %s", succeeded)


class AProcess(Proc):
input = "a"


if __name__ == "__main__":
Pipen(plugins=[NotifyPlugin]).set_starts(AProcess).run()
2 changes: 2 additions & 0 deletions examples/python-script.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from pipen import Pipen, Proc


class PythonScriptProc(Proc):
"""A process using python interpreter for script"""
input = "a"
Expand All @@ -13,5 +14,6 @@ class PythonScriptProc(Proc):
Path("{{out.outfile}}").write_text("{{in.a}}")
"""


if __name__ == "__main__":
Pipen().set_starts(PythonScriptProc).run()
9 changes: 8 additions & 1 deletion examples/retry.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import time
from pipen import Pipen, Proc


class RetryProc(Proc):
"""Retry the jobs when fail"""
input = "starttime"
Expand All @@ -10,13 +11,19 @@ class RetryProc(Proc):
# Make sure the job succeeds finally
num_retries = 10
script = """
if [[ $(date +"%s") -gt {{in.starttime + 3}} ]]; then
timefile="{{job.outdir}}/time.txt"
now=$(date +"%s")
expect={{in.starttime + 10}}
if [[ $now -gt $expect ]]; then
echo $now $expect 0 >> "$timefile"
exit 0
else
echo $now $expect 1 >> "$timefile"
exit 1
fi
"""


if __name__ == "__main__":
# Show debug information so we see the retrying message
Pipen(loglevel="debug").set_starts(RetryProc).run()

0 comments on commit 2a6ee82

Please sign in to comment.