forked from alphagov/search-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
72 lines (57 loc) · 1.7 KB
/
Rakefile
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
PROJECT_ROOT = File.dirname(__FILE__)
LIBRARY_PATH = File.join(PROJECT_ROOT, "lib")
[PROJECT_ROOT, LIBRARY_PATH].each do |path|
$LOAD_PATH.unshift(path) unless $LOAD_PATH.include?(path)
end
require "rummager"
require "rummager/config"
Dir[File.join(PROJECT_ROOT, "lib/tasks/**/*.rake")].each { |file| load file }
# rubocop:disable Lint/SuppressedException
begin
require "rspec/core/rake_task"
RSpec::Core::RakeTask.new(:spec)
rescue LoadError
end
# rubocop:enable Lint/SuppressedException
task default: %i[lint spec]
def logger
Logging.logger.root
end
def search_server(cluster: Clusters.default_cluster)
SearchConfig.instance(cluster).search_server
end
def clusters_from_args(args)
return Clusters.active unless args[:clusters].present?
derive_clusters(args[:clusters].split(" "))
end
def derive_clusters(cluster_keys = [])
unpermitted_cluster = cluster_keys.find { |key| Clusters.cluster_keys.exclude?(key) }
if unpermitted_cluster.present?
raise("`clusters` must be one of #{Clusters.cluster_keys.join(', ')}. \n
Leave this field blank to run against all clusters.")
end
Clusters.active.select { |cluster| cluster_keys.include? cluster.key }
end
def warn_for_single_cluster_run
puts "WARNING: this will only run on the default cluster."
end
def index_names
search_index = ENV["SEARCH_INDEX"]
case search_index
when "all"
SearchConfig.all_index_names
when String
[search_index]
else
raise "You must specify an index name in SEARCH_INDEX, or 'all'"
end
end
def max_index_age
max_age_in_days = ENV["MAX_INDEX_AGE"]
case max_age_in_days
when String
max_age_in_days
else
raise "You must specify the MAX_INDEX_AGE (e.g. MAX_INDEX_AGE=3)"
end
end