Module: Candygram::Utility
- Included in:
- Dispatch
- Defined in:
- lib/candygram/utility.rb
Overview
Various methods that may be useful to both delivery and dispatch.
Instance Method Summary collapse
-
#local_ip ⇒ Object
Returns the IP address of this machine relative to the MongoDB server.
-
#set_status(del, state) ⇒ Object
Pushes a new status message onto the job.
-
#update_succeeded?(result) ⇒ Boolean
Parses Mongo’s somewhat inscrutable results from Collection.update when :safe => true and returns whether or not the value was updated.
Instance Method Details
#local_ip ⇒ Object
Returns the IP address of this machine relative to the MongoDB server. From: coderrr.wordpress.com/2008/05/28/get-your-local-ip-address/
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/candygram/utility.rb', line 10 def local_ip @local_ip or begin orig, Socket.do_not_reverse_lookup = Socket.do_not_reverse_lookup, true # turn off reverse DNS resolution temporarily @local_ip = UDPSocket.open do |s| s.connect Candygram.connection.host, 1 s.addr.last end ensure Socket.do_not_reverse_lookup = orig end end |
#set_status(del, state) ⇒ Object
Pushes a new status message onto the job. Includes an identifier for this process and a timestamp.
31 32 33 |
# File 'lib/candygram/utility.rb', line 31 def set_status(del, state) Candygram.queue.update({'_id' => del['_id']}, {'$push' => {'status' => status_hash(state)}}) end |
#update_succeeded?(result) ⇒ Boolean
Parses Mongo’s somewhat inscrutable results from Collection.update when :safe => true and returns whether or not the value was updated. The basic output looks like this:
- [“updatedExisting”=>false, “n”=>0, “ok”=>1.0], 1, 0
26 27 28 |
# File 'lib/candygram/utility.rb', line 26 def update_succeeded?(result) result[0][0]["updatedExisting"] end |