-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathrepresent_downstream.rake
106 lines (95 loc) · 3.85 KB
/
represent_downstream.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
namespace :represent_downstream do
desc "Represent all editions downstream"
task all: :environment do
content_ids = Document.presented.pluck(:content_id)
Rake::Task["represent_downstream:content_id"].invoke(*content_ids)
end
desc "
Represent downstream for individual or multiple document_types
Usage
rake 'represent_downstream:document_type[:document_types]'
"
task :document_type, [:document_types] => :environment do |_t, args|
document_types = args[:document_types].split(" ")
content_ids = Document.presented.where(editions: { document_type: document_types }).pluck(:content_id)
Rake::Task["represent_downstream:content_id"].invoke(content_ids)
end
desc "
Represent downstream for a rendering application
Usage
rake 'represent_downstream:rendering_app[frontend]'
"
task :rendering_app, [:rendering_app] => :environment do |_t, args|
content_ids = Document.presented.where(editions: { rendering_app: args[:rendering_app] }).pluck(:content_id)
Rake::Task["represent_downstream:content_id"].invoke(content_ids)
end
desc "
Represent downstream for a publishing application
Usage
rake 'represent_downstream:publishing_app[frontend]'
"
task :publishing_app, [:publishing_app] => :environment do |_t, args|
content_ids = Document.presented.where(editions: { publishing_app: args[:publishing_app] }).pluck(:content_id)
Rake::Task["represent_downstream:content_id"].invoke(content_ids)
end
desc "Represent downstream content tagged to a parent taxon"
task tagged_to_taxon: :environment do
content_ids = Link.joins(:link_set).where(link_type: "taxons").pluck(:content_id)
Rake::Task["represent_downstream:content_id"].invoke(content_ids)
end
desc "
Represent an individual or multiple documents downstream
Usage
rake 'represent_downstream:content_id[57a1253c-68d3-4a93-bb47-b67b9b4f6b9a]'
"
task content_id: :environment do |_t, args|
content_ids = args.extras
queue = DownstreamQueue::HIGH_QUEUE
content_ids.uniq.each_slice(1000).each do |batch|
Commands::V2::RepresentDownstream.new.call(batch, queue:)
sleep 5
end
end
desc "
Represent downstream documents which were last updated in the given date
range. The time defaults to midnight if only a date is given, so date ranges
include the start date but exclude the end date.
Usage
rake 'represent_downstream:published_between[2018-01-15, 2018-01-20]'
rake 'represent_downstream:published_between[2018-01-04T09:30:00, 2018-01-04T16:00:00]'
"
task :published_between, %i[start_date end_date] => :environment do |_t, args|
content_ids = Document
.presented
.where(editions: { state: "published", last_edited_at: args[:start_date]..args[:end_date] })
.pluck(:content_id)
Rake::Task["represent_downstream:content_id"].invoke(content_ids)
end
namespace :high_priority do
desc "
Represent an individual or multiple documents downstream on the high priority
sidekiq queue
Usage
rake 'represent_downstream:high_priority:content_id[57a1253c-68d3-4a93-bb47-b67b9b4f6b9a]'
"
task content_id: :environment do |_t, args|
content_ids = args.extras
queue = DownstreamQueue::HIGH_QUEUE
content_ids.uniq.each_slice(1000).each do |batch|
Commands::V2::RepresentDownstream.new.call(batch, queue:)
sleep 5
end
end
desc "
Represent documents by document type(s) downstream on the high_priority sidekiq
queue
Usage
rake 'represent_downstream:high_priority:document_type[NewsArticle]'
"
task :document_type, [:document_types] => :environment do |_t, args|
document_types = args[:document_types].split(" ")
content_ids = Document.presented.where(editions: { document_type: document_types }).pluck(:content_id)
Rake::Task["represent_downstream:high_priority:content_id"].invoke(content_ids)
end
end
end