0
我正在导入gmail联系人,有些用户拥有大量联系人,需要很长时间才能保存到数据库中。如何在延迟作业中使用以异步方式在后台运行。 我使用delay_job宝石使用延迟工作保存导入gmail联系人
这里是代码我写
token = Google::Authorization.exchange_singular_use_for_session_token(params[:token])
unless token == false
@contacts = Google::Contact.all(token)
@contacts.each do |contact|
next if contact.email.nil?
c = {
:user_id => current_user.id,
:source => 'gmail',
:name => contact.name,
:email => contact.email
}
c = Contact.find_or_initialize_by_email(c[:email])
c.update_attributes(c)
end
end