From e78d8e6358edaf1cc15e30444d4381348e57ca36 Mon Sep 17 00:00:00 2001 From: Mauro Amico Date: Wed, 21 Mar 2012 03:12:49 +0100 Subject: [PATCH 1/6] delay --- docs/httpok.rst | 4 ++++ superlance/httpok.py | 20 ++++++++++++++++---- superlance/tests/httpok_test.py | 26 +++++++++++++++++++++++--- 3 files changed, 43 insertions(+), 7 deletions(-) diff --git a/docs/httpok.rst b/docs/httpok.rst index 52541a3..e8de3ca 100644 --- a/docs/httpok.rst +++ b/docs/httpok.rst @@ -117,6 +117,10 @@ Command-Line Syntax Disable "eager" monitoring: do not check the URL or emit mail if no monitored process is in the RUNNING state. +.. cmdoption:: -w , --delay= + + Number of seconds delay before really make a restart. + .. cmdoption:: The URL to which to issue a GET request. diff --git a/superlance/httpok.py b/superlance/httpok.py index 49dc983..20ad78e 100644 --- a/superlance/httpok.py +++ b/superlance/httpok.py @@ -26,7 +26,7 @@ doc = """\ httpok.py [-p processname] [-a] [-g] [-t timeout] [-c status_code] [-b inbody] - [-m mail_address] [-s sendmail] URL + [-m mail_address] [-s sendmail] [-w delay_seconds] URL Options: @@ -81,6 +81,8 @@ -E -- not "eager": do not check URL / emit mail if no process we are monitoring is in the RUNNING state. + +-w -- specify number of seconds delay before really make a restart. URL -- The URL to which to issue a GET request. @@ -113,7 +115,8 @@ def usage(): class HTTPOk: connclass = None def __init__(self, rpc, programs, any, url, timeout, status, inbody, - email, sendmail, coredir, gcore, eager): + email, sendmail, coredir, gcore, eager, delay): + self.rpc = rpc self.programs = programs self.any = any @@ -126,6 +129,7 @@ def __init__(self, rpc, programs, any, url, timeout, status, inbody, self.coredir = coredir self.gcore = gcore self.eager = eager + self.delay = delay self.stdin = sys.stdin self.stdout = sys.stdout self.stderr = sys.stderr @@ -263,6 +267,10 @@ def mail(self, email, subject, msg): def restart(self, spec, write): namespec = make_namespec(spec['group'], spec['name']) if spec['state'] is ProcessStates.RUNNING: + if self.delay and (spec['now']-spec['start']) Date: Fri, 21 Sep 2012 19:14:46 +0200 Subject: [PATCH 2/6] travis --- .travis.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..2f73dcf --- /dev/null +++ b/.travis.yml @@ -0,0 +1,12 @@ +language: python +python: + - 2.4 + - 2.6 + - 2.7 +before_install: +install: +script: + - python test + + + From d2e1b29f1b4f3c60696dfc6128caa6dd0ccf32d4 Mon Sep 17 00:00:00 2001 From: Mauro Amico Date: Fri, 21 Sep 2012 22:01:31 +0200 Subject: [PATCH 3/6] travis (fix) --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 2f73dcf..d175241 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,7 @@ python: before_install: install: script: - - python test + - python setup.py test From f15c1aec38e22824c76971d2c580dfe93ff08f44 Mon Sep 17 00:00:00 2001 From: Mauro Amico Date: Fri, 21 Sep 2012 22:17:40 +0200 Subject: [PATCH 4/6] travis (python 2.4 removed) --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index d175241..5ed2bc5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,5 @@ language: python python: - - 2.4 - 2.6 - 2.7 before_install: From 0b6e9be0dde3c27e47e7940edfdab81a270fa5d2 Mon Sep 17 00:00:00 2001 From: mamico Date: Thu, 15 Jan 2015 14:41:48 +0100 Subject: [PATCH 5/6] fix delay param --- superlance/httpok.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/superlance/httpok.py b/superlance/httpok.py index 8dd935a..d085b61 100644 --- a/superlance/httpok.py +++ b/superlance/httpok.py @@ -342,6 +342,7 @@ def main(argv=sys.argv): email = None timeout = 10 retry_time = 10 + delay = None status = '200' inbody = None @@ -384,7 +385,7 @@ def main(argv=sys.argv): eager = False if option in ('-w', '--delay'): - delay = value + delay = int(value) url = arguments[-1] From 233a9ddc5af57a16c87ad5b8d94048070cfeed1f Mon Sep 17 00:00:00 2001 From: mamico Date: Sat, 21 Feb 2015 18:56:25 +0100 Subject: [PATCH 6/6] fix py3 test --- superlance/tests/httpok_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/superlance/tests/httpok_test.py b/superlance/tests/httpok_test.py index 9e53f09..6b3ac36 100644 --- a/superlance/tests/httpok_test.py +++ b/superlance/tests/httpok_test.py @@ -320,7 +320,7 @@ def test_runforever_not_eager_running_delay150(self): prog.stdin.write('eventname:TICK len:0\n') prog.stdin.seek(0) prog.runforever(test=True) - lines = filter(None, prog.stderr.getvalue().split('\n')) + lines = [x for x in prog.stderr.getvalue().split('\n') if x] self.assertEqual(lines[0], ("Restarting selected processes ['foo', 'bar']") )