Sha256: fbc2327896b97569d2b4ae45a92bdbc005bfd4cc089084dff755c3cf1d4832f9

Contents?: true

Size: 1.81 KB

Versions: 1

Compression:

Stored size: 1.81 KB

Contents

require 'eventbus/message'

class MessagesController < ApplicationController
  # GET /messages
  # GET /messages.json
  def index
    conditions = {}
    
    unless params['message'].nil?
      
      if params['message']['is_error'] == 1
        params['message']['is_error'] = true
      else
        params['message'].delete('is_error')
      end
      
      params['message'].each_pair do | field, filter |
        conditions[field] = filter unless filter.nil? or filter.blank?
      end
    end
    
    logger.info "*** Filtering on conditions: #{conditions}"
  
    @messages = Message.where(conditions).limit(75).reverse_order

    respond_to do |format|
      format.html # index.html.erb
      format.json { render json: @messages }
    end
  end

  # GET /messages/1
  # GET /messages/1.json
  def show
    @message = Message.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.json { render json: @message }
    end
  end
  
  def resubmit_event
    @message = Message.find(params[:id])
    logger.info "Params: #{params.inspect}"
    logger.info "Resubmit will have status: #{params[:message][:status]}"
    resubmit_to_queue(params[:message][:status])
    redirect_to messages_path
  end
  
  def send_queue
    @message = Message.find(params[:id])
    q = params[:message][:dispatch_to]
    resubmit_to_queue(nil, q)
    redirect_to messages_path
  end
  
  private
  
  def resubmit_to_queue(status = nil, queue="dispatcher")
    m = EventBus::Message.new("EVENTBUS_CORE")
    m.load(@message.content)
    m.status = status unless status.nil?
    
    system_queue = queue == "dispatcher" ? true : false
    
    m.send :queue_name => queue, :system_queue => system_queue
    
    logger.info "Resubmitted to queue: #{queue}"
    logger.info "Message content:"
    logger.info m.dump

  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
eventbus-0.0.20 admin/app/controllers/messages_controller.rb