summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Kemp <steve@steve.org.uk>2012-11-18 15:22:33 +0000
committerSteve Kemp <steve@steve.org.uk>2012-11-18 15:22:33 +0000
commit550c7c27446bb2381dba82fb6355363a29504a75 (patch)
tree83cbfca252d1f1300a9c4603e2b178325011c791
parent787760f930ce2afddb5a5d2093773e47818701cf (diff)
Ensure that the job we pull from the queue is a non-empty hash.
-rw-r--r--lib/custodian.rb18
1 files changed, 17 insertions, 1 deletions
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'] )