Skip to content

Instantly share code, notes, and snippets.

@netmarkjp
Created February 2, 2013 07:44
Show Gist options
  • Save netmarkjp/4696483 to your computer and use it in GitHub Desktop.
Save netmarkjp/4696483 to your computer and use it in GitHub Desktop.
# 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