Skip to content

Commit 889ec60

Browse files
committed
Provide a msgflo.main(), use in example
1 parent db8db64 commit 889ec60

File tree

3 files changed

+11
-23
lines changed

3 files changed

+11
-23
lines changed

bin/msgflo-python

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,7 @@ def main():
3333
module = load_module_file(modulepath)
3434
classes = find_participant_classes(module)
3535
Participant = classes[0]
36-
37-
participant = Participant(role)
38-
d = participant.definition
39-
waiter = gevent.event.AsyncResult()
40-
engine = msgflo.run(participant, done_cb=waiter.set)
41-
print "%s(%s) running on %s" % (d['role'], d['component'], engine.broker_url)
42-
sys.stdout.flush()
43-
waiter.wait()
36+
msgflo.main(Participant)
4437

4538
if __name__ == '__main__':
4639
logging.basicConfig()

examples/repeat.py

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,6 @@ def process(self, inport, msg):
1818
self.send('out', msg.data)
1919
self.ack(msg)
2020

21-
22-
def main():
23-
waiter = gevent.event.AsyncResult()
24-
role = sys.argv[1] if len(sys.argv) > 1 else 'repeat'
25-
repeater = Repeat(role)
26-
engine = msgflo.run(repeater, done_cb=waiter.set)
27-
28-
print "Repeat running on %s" % (engine.broker_url)
29-
sys.stdout.flush()
30-
waiter.wait()
31-
print "Shutdown"
32-
sys.stdout.flush()
33-
3421
if __name__ == '__main__':
35-
logging.basicConfig()
36-
main()
22+
msgflo.main(Repeat)
3723

msgflo/msgflo.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,3 +288,12 @@ def run(participant, broker=None, done_cb=None):
288288
engine.run()
289289

290290
return engine
291+
292+
def main(Participant):
293+
participant = Participant(role)
294+
d = participant.definition
295+
waiter = gevent.event.AsyncResult()
296+
engine = msgflo.run(participant, done_cb=waiter.set)
297+
print "%s(%s) running on %s" % (d['role'], d['component'], engine.broker_url)
298+
sys.stdout.flush()
299+
waiter.wait()

0 commit comments

Comments
 (0)