Skip to content

Instantly share code, notes, and snippets.

@RobertKim
Created October 25, 2016 16:34
Show Gist options
  • Save RobertKim/9cdec111899fcb4984b40f57ec65a142 to your computer and use it in GitHub Desktop.
Save RobertKim/9cdec111899fcb4984b40f57ec65a142 to your computer and use it in GitHub Desktop.
Rake tasks for mass creation of project records for AWR Cloud with their API, in sync with local database project records.
require 'salesforce_parc'
namespace :rankings do
desc ""
task :create_all_projects => :environment do
begin
AwrcloudApiCall.if_free_calls -> do
puts "Started creating rankings projects... #{Time.now}"
api = RubyTrac::API.new Rails.application.secrets.leadtrac_username, Rails.application.secrets.leadtrac_password
leadtrac_numbers = api.soap(:search_by_status, {statusId: 13026}).body[:search_by_status_response][:search_by_status_result][:string]
total = leadtrac_numbers.count
last_file_number = File.open('awrcloud.txt', &:readline).chomp rescue nil
resume_index = leadtrac_numbers.index(last_file_number) || 0
Project.create_for_file_numbers leadtrac_numbers, User, Ranking, AwrcloudApiCall, RankingsAPI, resume_index
puts "Finished creating rankings projects. #{Time.now}"
`curl https://nosnch.in/875ec573c3`
end
rescue => e
puts e
ensure
AwrcloudApiCall.cleanup
end
end
desc ""
task :create_projects => :environment do
begin
AwrcloudApiCall.if_free_calls -> do
puts "#{Time.now} | Started creating rankings projects..."
sf = SalesForceapi.new
sf_domains = sf.active_clients_domains_array
kevins_domains = [sf_domains].flatten.uniq.map! { |e| e.include?("www.") ? e.sub(/^https?\:\/\//, '').gsub(/^www./,'') : e }
existing_project_domains = ActiveRecord::Base.connection.execute("SELECT domain FROM projects").map{|d| d[0].printable_only}
domains_to_create_projects = kevins_domains.reject{|d| existing_project_domains.include?(d.printable_only)}
puts "Domains remaining: #{domains_to_create_projects.count}"
Project.create_for_domains(domains_to_create_projects, User, Ranking, AwrcloudApiCall, RankingsAPI, 0)
puts "#{Time.now} | Finished creating rankings projects."
`curl https://nosnch.in/875ec573c3`
end
rescue => e
puts e
ensure
AwrcloudApiCall.cleanup
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment