Last active
August 29, 2015 14:10
-
-
Save k4nar/25dddf2cd6f1590d257d to your computer and use it in GitHub Desktop.
Circus start callback
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
import time | |
import circus | |
import redis | |
from tornado import gen | |
@gen.coroutine | |
def start_workers(*args, **kwargs): | |
client = redis.Redis() | |
# We wait for redis to be up | |
while True: | |
try: | |
client.ping() | |
except redis.exceptions.ConnectionError: | |
time.sleep(0.05) | |
else: | |
break | |
# We asume that the 'workers' key contains a list of commands | |
# to launch | |
for i, worker in enumerate(client.lrange('workers', 0, -1)): | |
watcher = arbiter.add_watcher( | |
'Worker %s' % i, | |
worker, | |
) | |
yield watcher.start() | |
if __name__ == '__main__': | |
arbiter = circus.get_arbiter( | |
( | |
{'name': 'Redis', 'cmd': 'redis-server'}, | |
) | |
) | |
arbiter.start(cb=start_workers) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment