user_info_list.eachdo |id,attributes| user_info_list[id] = attributes.select{|k,v| v && v!=""} end
#user_info_list = user_info_list.compact #将数据更新到数据库里面 WeiXinBind.Base.connection do transcation WeiXinBind.update(user_info_list.keys,user_info_list.values) end end
def send_request_in_batch(request_url_list,user_info_list) EM.run do cnt = 0 request_url_list.eachdo |url,id|
http = EventMachine::HttpRequest.new(url).get http.errback { cnt += 1 if cnt == request_url_list.count - 1 EM.stop end } http.callback { resp = Oj.load(http.response) if !resp.blank? && resp["subscribe"] == 1 user_info_list[id] = {nickname:resp["nickname"],headimg_url:resp["headimgurl"], sex:resp["sex"], province:resp["province"], city:resp["city"], country:resp["country"]} end cnt += 1 if cnt == request_url_list.count - 1 EM.stop end } end end end