Skip to content

Commit

Permalink
clean up rake tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Jan 12, 2019
1 parent 8b09d59 commit 0a94dce
Show file tree
Hide file tree
Showing 7 changed files with 139 additions and 171 deletions.
112 changes: 66 additions & 46 deletions lib/tasks/client.rake
Original file line number Diff line number Diff line change
@@ -1,4 +1,70 @@
namespace :client do
desc "Create index for clients"
task :create_index => :environment do
Client.__elasticsearch__.create_index!
end

desc "Delete index for clients"
task :delete_index => :environment do
Client.__elasticsearch__.delete_index!
end

desc "Refresh index for clients"
task :refresh_index => :environment do
Client.__elasticsearch__.refresh_index!
end

desc 'Index DOIs by client'
task :index_all_dois => :environment do
if ENV['CLIENT_ID'].nil?
puts "ENV['CLIENT_ID'] is required."
exit
end

client = Client.where(deleted_at: nil).where(symbol: ENV['CLIENT_ID']).first
if client.nil?
puts "Client not found for client ID #{ENV['CLIENT_ID']}."
exit
end

# index DOIs for client
puts "#{client.dois.length} DOIs will be indexed."
client.dois.find_each do |doi|
doi.__elasticsearch__.index_document
puts "DOI #{doi.doi} indexed."
end
end

desc 'Import all clients'
task :import => :environment do
Client.import
end

desc 'Import DOIs by client'
task :import_all_dois => :environment do
if ENV['CLIENT_ID'].nil?
puts "ENV['CLIENT_ID'] is required."
exit
end

client = Client.where(deleted_at: nil).where(symbol: ENV['CLIENT_ID']).first
if client.nil?
puts "Client not found for client ID #{ENV['CLIENT_ID']}."
exit
end

# import DOIs for client
puts "#{client.dois.length} DOIs will be imported."
client.dois.find_each do |doi|
begin
Doi.import_one(doi_id: doi.doi)
puts "DOI #{doi.doi} imported."
rescue TypeError, NoMethodError, RuntimeError, ActiveRecord::StatementInvalid, ActiveRecord::LockWaitTimeout, Elasticsearch::Transport::Transport::Errors::BadRequest => error
puts "[MySQL] Error importing metadata for " + doi.doi + ": " + error.message
end
end
end

desc 'Delete client transferred to other DOI registration agency'
task :delete => :environment do
if ENV['CLIENT_ID'].nil?
Expand Down Expand Up @@ -107,50 +173,4 @@ namespace :client do
puts "Client prefix for client #{target.symbol} and prefix #{prefix} created."
end
end

desc 'Import DOIs by client'
task :import_all_dois => :environment do
if ENV['CLIENT_ID'].nil?
puts "ENV['CLIENT_ID'] is required."
exit
end

client = Client.where(deleted_at: nil).where(symbol: ENV['CLIENT_ID']).first
if client.nil?
puts "Client not found for client ID #{ENV['CLIENT_ID']}."
exit
end

# import DOIs for client
puts "#{client.dois.length} DOIs will be imported."
client.dois.find_each do |doi|
begin
Doi.import_one(doi_id: doi.doi)
puts "DOI #{doi.doi} imported."
rescue TypeError, NoMethodError, RuntimeError, ActiveRecord::StatementInvalid, ActiveRecord::LockWaitTimeout, Elasticsearch::Transport::Transport::Errors::BadRequest => error
puts "[MySQL] Error importing metadata for " + doi.doi + ": " + error.message
end
end
end

desc 'Index DOIs by client'
task :index_all_dois => :environment do
if ENV['CLIENT_ID'].nil?
puts "ENV['CLIENT_ID'] is required."
exit
end

client = Client.where(deleted_at: nil).where(symbol: ENV['CLIENT_ID']).first
if client.nil?
puts "Client not found for client ID #{ENV['CLIENT_ID']}."
exit
end

# index DOIs for client
puts "#{client.dois.length} DOIs will be indexed."
client.dois.find_each do |doi|
doi.__elasticsearch__.index_document
puts "DOI #{doi.doi} indexed."
end
end
end
81 changes: 51 additions & 30 deletions lib/tasks/doi.rake
Original file line number Diff line number Diff line change
@@ -1,9 +1,40 @@
namespace :doi do
desc 'Store handle URL'
task :set_url => :environment do
from_date = ENV['FROM_DATE'] || (Time.zone.now - 1.day).strftime("%F")
response = Doi.set_url(from_date: from_date)
puts response
desc 'Index all DOIs'
task :index => :environment do
if ENV['YEAR'].present?
from_date = "#{ENV['YEAR']}-01-01"
until_date = "#{ENV['YEAR']}-12-31"
else
from_date = ENV['FROM_DATE'] || Date.current.strftime("%F")
until_date = ENV['UNTIL_DATE'] || Date.current.strftime("%F")
end

index_time = ENV['INDEX_TIME'] || Time.zone.now.utc.iso8601
client_id = ENV['CLIENT_ID']

Doi.index(from_date: from_date, until_date: until_date, index_time: index_time, client_id: client_id)
end

desc 'Index DOIs per day'
task :index_by_day => :environment do
from_date = ENV['FROM_DATE'] || Date.current.strftime("%F")

Doi.index_by_day(from_date: from_date)
puts "DOIs created on #{from_date} indexed."
end

desc 'Index DOIs by ID'
task :index_by_ids => :environment do
from_id = (ENV['FROM_ID'] || 1).to_i
until_id = (ENV['UNTIL_ID'] || from_id + 499).to_i

Doi.index_by_ids(from_id: from_id, until_id: until_id)
end

desc 'Import all dois'
task :import => :environment do
Doi.__elasticsearch__.create_index!
Doi.import
end

desc 'Import all DOIs'
Expand Down Expand Up @@ -50,36 +81,26 @@ namespace :doi do
Doi.import_one(doi_id: ENV['DOI'])
end

desc 'Index all DOIs'
task :index => :environment do
if ENV['YEAR'].present?
from_date = "#{ENV['YEAR']}-01-01"
until_date = "#{ENV['YEAR']}-12-31"
else
from_date = ENV['FROM_DATE'] || Date.current.strftime("%F")
until_date = ENV['UNTIL_DATE'] || Date.current.strftime("%F")
end

index_time = ENV['INDEX_TIME'] || Time.zone.now.utc.iso8601
client_id = ENV['CLIENT_ID']

Doi.index(from_date: from_date, until_date: until_date, index_time: index_time, client_id: client_id)
desc "Create index for dois"
task :create_index => :environment do
Doi.__elasticsearch__.create_index!
end

desc 'Index DOIs per day'
task :index_by_day => :environment do
from_date = ENV['FROM_DATE'] || Date.current.strftime("%F")

Doi.index_by_day(from_date: from_date)
puts "DOIs created on #{from_date} indexed."
desc "Delete index for dois"
task :delete_index => :environment do
Doi.__elasticsearch__.delete_index!
end

desc 'Index DOIs by ID'
task :index_by_ids => :environment do
from_id = (ENV['FROM_ID'] || 1).to_i
until_id = (ENV['UNTIL_ID'] || from_id + 499).to_i
desc "Refresh index for dois"
task :refresh_index => :environment do
Doi.__elasticsearch__.refresh_index!
end

Doi.index_by_ids(from_id: from_id, until_id: until_id)
desc 'Store handle URL'
task :set_url => :environment do
from_date = ENV['FROM_DATE'] || (Time.zone.now - 1.day).strftime("%F")
response = Doi.set_url(from_date: from_date)
puts response
end

desc 'Set minted'
Expand Down
23 changes: 0 additions & 23 deletions lib/tasks/elasticsearch/client.rake

This file was deleted.

24 changes: 0 additions & 24 deletions lib/tasks/elasticsearch/doi.rake

This file was deleted.

24 changes: 0 additions & 24 deletions lib/tasks/elasticsearch/prefix.rake

This file was deleted.

24 changes: 0 additions & 24 deletions lib/tasks/elasticsearch/provider.rake

This file was deleted.

22 changes: 22 additions & 0 deletions lib/tasks/provider.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
namespace :provider do
desc 'Import all providers'
task :import => :environment do
Provider.__elasticsearch__.create_index!
Provider.import
end

desc "Create index for providers"
task :create_index => :environment do
Provider.__elasticsearch__.create_index!
end

desc "Delete index for providers"
task :delete_index => :environment do
Provider.__elasticsearch__.delete_index!
end

desc "Refresh index for providers"
task :refresh_index => :environment do
Provider.__elasticsearch__.refresh_index!
end
end

0 comments on commit 0a94dce

Please sign in to comment.