namespace :horst do
  desc "Subscriber for horst data"
  task subscribe: :environment do
    redis = Redis.connect(:host => APPLICATION[Rails.env]["redis"]["host"], :port => APPLICATION[Rails.env]["redis"]["port"])	
    redis.subscribe("horst") do |on|
      on.message do |channel, message|
	p "Horst : ",message
        p_data = $redis.lpop('presence')
        p "Horst : ",p_data
        unless p_data.blank? 
          if p_data.include?("probing")
            m = URI.unescape(p_data)
            m.gsub!("data=","")
            ScanningData.save_data(JSON.parse(m))
          else
            ScanningData.save_data(JSON.parse(message))
          end
        end
      end
    end
  end
end
