Skip to content

Instantly share code, notes, and snippets.

@k4nar
Last active August 29, 2015 14:10
Show Gist options
  • Save k4nar/25dddf2cd6f1590d257d to your computer and use it in GitHub Desktop.
Save k4nar/25dddf2cd6f1590d257d to your computer and use it in GitHub Desktop.
Circus start callback
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