lib/cloudist/job.rb in cloudist-0.0.2 vs lib/cloudist/job.rb in cloudist-0.0.3

- old
+ new

@@ -19,28 +19,41 @@ def cleanup end - def reply(data, headers = {}) - # headers.update(:message_id => payload.headers[:message_id]) + def reply(data, headers = {}, options = {}) + options = { + :echo => false + }.update(options) + headers = { :message_id => payload.headers[:message_id], - :reply_type => "reply" + :message_type => "reply" }.update(headers) + # Echo the payload back + data.merge!(payload.body) if options[:echo] == true + reply_payload = Payload.new(data, headers) reply_queue = ReplyQueue.new(payload.reply_to) reply_queue.setup - reply_queue.publish_to_q(reply_payload) + published_headers = reply_queue.publish_to_q(reply_payload) - # log.debug("Replying: #{data.inspect} - Payload: #{reply_payload.inspect}") + log.debug("Replying: #{data.inspect} - Headers: #{published_headers.inspect}") end - def event(event_name, data = {}) - data = {} unless data - reply({:event => event_name}.merge(payload.body), {:reply_type => "event"}) + # Sends a progress update + # Inputs: percentage - Integer + # Optional description, this could be displayed to the user e.g. Resizing image + def progress(percentage, description = nil) + reply({:progress => percentage, :description => description}, {:message_type => 'progress'}) + end + + def event(event_name, event_data = {}, options = {}) + event_data = {} if event_data.nil? + reply(event_data, {:event => event_name, :message_type => 'event'}, options) end def method_missing(meth, *args, &blk) if meth.to_s.ends_with?("!") event(meth.to_s.gsub(/(!)$/, ''), args.shift)