I am importing gmail contacts, some users had huge number of contacts its taking long time to save in database. How to use in delay job to run in background asynchronously. I am using delay_job gem
Here is code I wrote
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