Skip to content

Commit

Permalink
Add example 4, demonstrating how to run meta workflow of multiple wor…
Browse files Browse the repository at this point in the history
…kflows
  • Loading branch information
samuell committed Oct 26, 2015
1 parent f212cfb commit a28e821
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions examples/example4_multiwf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
'''
An example showing how you can run multiple workflow tasks, from a "Meta workflow" (MetaWF below)
'''

import sciluigi as sl
import luigi

class MetaWF(sl.WorkflowTask):
'''
Meta workflow
'''
def workflow(self):
tasks = []
for r in ['bar', 'tjo', 'hej']:
wf = self.new_task('wf', WF, replacement=r)
tasks.append(wf)
return tasks

class WF(sl.WorkflowTask):
'''
Main workflow, which is run in multiple instances above
'''
replacement = luigi.Parameter()
def workflow(self):
t1 = self.new_task('foowriter', FooWriter)
t2 = self.new_task('foo2bar', Foo2Bar, replacement=self.replacement)
t2.in_foo = t1.out_foo
return t2

class FooWriter(sl.Task):
'''
A dummy task
'''
def out_foo(self):
return sl.TargetInfo(self, 'foo.txt')
def run(self):
self.ex('echo foo > {foo}'.format(
foo=self.out_foo().path))

class Foo2Bar(sl.Task):
'''
Another dummy task
'''
replacement = luigi.Parameter()
in_foo = sl.TargetInfo(None, 'None')
def out_bar(self):
return sl.TargetInfo(self, self.in_foo().path + '.{r}.txt'.format(r=self.replacement))
def run(self):
self.ex('sed "s/foo/{r}/g" {inf} > {outf}'.format(
r=self.replacement,
inf=self.in_foo().path,
outf=self.out_bar().path)
)

# Run as script
if __name__ == '__main__':
sl.run_local()

0 comments on commit a28e821

Please sign in to comment.