Created
February 2, 2013 07:44
-
-
Save netmarkjp/4696483 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# pip install redis | |
import redis | |
QUEUE="scale:sclgrp:up" | |
LOCK_KEY="scale:sclgrp:lock" | |
INCRD_KEY="scale:sclgrp:incrd" | |
def scaleout(): | |
r = redis.StrictRedis() | |
queue_count=r.llen(QUEUE) | |
locked=r.get(LOCK_KEY) | |
print locked | |
if queue_count > 0 and locked: | |
print "scaleout in progress" | |
if queue_count > 0 and not locked: | |
r.set(LOCK_KEY,0) | |
num=r.get(INCRD_KEY) | |
incrd=num if num else 0 | |
setup_idcf_vm("scale_%(num)s"%{'num':incrd}) | |
r.delete(QUEUE,0) | |
r.delete(LOCK_KEY,0) | |
r.incr(INCRD_KEY) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment