From ae3f7608d4cbd7284685ed7c85b92a4961cb90c5 Mon Sep 17 00:00:00 2001 From: Rui Carmo Date: Sat, 2 Apr 2016 17:46:11 +0100 Subject: [PATCH] Prevent scaling web/wsgi above a single worker (but allow turning them off) --- README.md | 2 +- piku.py | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 33f537f..1c1a500 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ From the bottom up: - [ ] Support barebones binary deployments - [ ] CLI command documentation - [ ] Complete installation instructions (see `INSTALL.md` for a working draft) -- [ ] Worker scaling +- [x] Worker scaling - [x] Remote CLI commands for changing/viewing applied/live settings - [x] Remote tailing of all logfiles for a single application - [x] HTTP port selection (and per-app environment variables) diff --git a/piku.py b/piku.py index bb74293..41bb96f 100644 --- a/piku.py +++ b/piku.py @@ -502,11 +502,17 @@ def deploy_app(app, settings): for s in settings: try: k, v = map(lambda x: x.strip(), s.split(":", 1)) + c = int(v) # check for integer value if k not in worker_count: echo("Error: worker type '%s' not present in '%s'" % (k, app), fg='red') return - _ = int(v) # check for integer value - worker_count[k] = v + elif k in ['web','wsgi'] and 0 <= c < 1: + echo("Error: cannot scale type '%s' above 1" % k, fg='red') + return + if c < 0 and int(worker_count[k] - c) >= 0: + v = worker_count[k] = worker_count[k] - c + else: + worker_count[k] = v echo("Scaling %s to %s for '%s'" % (k, v, app), fg='white') except: echo("Error: malformed setting '%s'" % s, fg='red')