-
Notifications
You must be signed in to change notification settings - Fork 0
/
atom.rake
50 lines (44 loc) · 1.94 KB
/
atom.rake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# frozen_string_literal: true
require 'merritt/atom'
namespace :atom do
desc 'Generic Atom to Merritt processor'
task :update, Merritt::Atom::Harvester::ARG_KEYS do |_, task_args|
arg_hash = task_args.to_h
delay, batch_size = throttler(task_args.extras)
args = arg_hash.merge(delay: delay.to_i, batch_size: batch_size.to_i)
processor = Merritt::Atom::Harvester.new(args)
processor.log_info("Initialized harvester: #{args.map { |k, v| "#{k}: #{v}" }.join(', ')}")
processor.process_feed!
end
# rubocop:disable Layout/LineLength
# Usage example:
#
# bundle exec rake atom:gen_csh['production',UCM Ramicova','https://s3.amazonaws.com/static.ucldc.cdlib.org/merritt/ucldc_collection_26098.atom','ucm_lib_nuxeo','ark:/13030/m5b58sn8','Merced Library Nuxeo collection']
# rubocop:enable Layout/LineLength
desc 'Generate CSH script for Atom feed harvesting'
task :gen_csh, Merritt::Atom::CSHGenerator::ARG_KEYS do |_, task_args|
csh_source = Merritt::Atom::CSHGenerator.generate_csh(task_args.to_hash)
puts csh_source
end
# rubocop:disable Layout/LineLength
# The CSV file should be in the format:
#
# environment,nuxeo_collection_name,feed_url,merritt_collection_mnemonic,merritt_collection_ark,merritt_collection_name
#
# Usage example:
#
# bundle exec rake atom:csv_to_csh[/tmp/feeds.csv,../mrt-dashboard-config/atom/bin]
# rubocop:enable Layout/LineLength
desc 'Read the specified CSV file and write Atom feed harvest scripts to the specified directory'
task :csv_to_csh, %i[csv_file to_dir] do |_, task_args|
csv_data = File.read(task_args[:csv_file])
to_dir = task_args[:to_dir]
count = Merritt::Atom::CSHGenerator.from_csv(csv_data: csv_data, to_dir: to_dir)
target_dir = File.realpath(to_dir)
puts "Wrote #{count} CSH scripts to #{target_dir}"
end
def throttler(extras)
return extras if extras.any?
[Merritt::Atom::DEFAULT_DELAY, Merritt::Atom::DEFAULT_BATCH_SIZE]
end
end