Skip to content

Open-source live-chat, email support, omni-channel desk. An alternative to Intercom, Zendesk, Salesforce Service Cloud etc. 🔥💬

826 B
Raw Blame
module DataImports::ImportJob
  def perform(data_import, run_id = nil)
    return if skip_import?(data_import, run_id)

    importer = importer_for(data_import, run_id)
    return unless importer.start!

    enqueue_next_stage(data_import, importer, run_id)
  rescue StandardError => e
    fail_unexpected_error(importer, e)
  end

  private

  def enqueue_next_stage(data_import, importer, run_id)
    if importer.import_contacts? && !importer.contacts_completed?
      contacts_page_job_class(data_import).perform_later(data_import, importer.cursor_for('contacts'), run_id)
    elsif importer.import_conversations? && !importer.conversations_completed?
      conversations_page_job_class(data_import).perform_later(data_import, importer.cursor_for('conversations'), run_id)
    else
      importer.finish!
    end
  end
end