From 0ed05e3cb2ff25266429d1b4fbcefbe907093077 Mon Sep 17 00:00:00 2001 From: Steve Kemp Date: Sun, 18 Nov 2012 15:22:33 +0000 Subject: Ensure that the job we pull from the queue is a non-empty hash. --- lib/custodian.rb | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'lib/custodian.rb') diff --git a/lib/custodian.rb b/lib/custodian.rb index 821bf6d..6c0ec81 100644 --- a/lib/custodian.rb +++ b/lib/custodian.rb @@ -111,10 +111,26 @@ class Custodian # - # Parse the JSON of the job body. + # Get the job body # json = job.body + raise ArgumentError, "Body doesn't look like JSON" unless( json =~ /[{}]/ ) + + + # + # Decode the JSON body - it should return a non-empty hash. + # hash = JSON.parse( json ) + + # + # Ensure we got a non-empty hash. + # + raise ArgumentError, "JSON didn't decode to a hash" unless hash.kind_of?(Hash) + raise ArgumentError, "JSON hash is empty" if (hash.empty?) + + # + # Are we being verbose? + # hash['verbose'] = 1 if ( ENV['VERBOSE'] ) -- cgit v1.2.1