|
1 | 1 | class RequeueContent |
2 | | - def initialize(number_of_items: nil) |
3 | | - @number_of_items = number_of_items |
| 2 | + def initialize(scope) |
| 3 | + # Restrict scope to stuff that's live (published or unpublished) |
| 4 | + # Unpublished content without a content store representation won't |
| 5 | + # be returned, but we're not interested in this content. |
| 6 | + @scope = scope.where(content_store: :live) |
| 7 | + @version = Event.maximum(:id) |
4 | 8 | end |
5 | 9 |
|
6 | | - attr_accessor :number_of_items |
7 | | - |
8 | 10 | def call |
9 | | - if number_of_items.present? |
10 | | - Edition.where(state: :published).limit(number_of_items).each do |edition| |
11 | | - publish_to_queue(edition) |
12 | | - end |
13 | | - else |
14 | | - Edition.where(state: :published).find_each do |edition| |
15 | | - publish_to_queue(edition) |
16 | | - end |
| 11 | + scope.each do |edition| |
| 12 | + publish_to_queue(edition) |
17 | 13 | end |
18 | 14 | end |
19 | 15 |
|
20 | 16 | private |
21 | 17 |
|
22 | | - def publish_to_queue(edition) |
23 | | - version = Event.maximum(:id) |
24 | | - |
25 | | - queue_payload = Presenters::EditionPresenter.new( |
26 | | - edition, draft: false, |
27 | | - ).for_message_queue(version) |
| 18 | + attr_reader :scope, :version |
28 | 19 |
|
29 | | - # FIXME: Rummager currently only listens to the message queue for the |
30 | | - # event type 'links'. This behaviour will eventually be updated so that |
31 | | - # it listens to other update types as well. This will happen as part of |
32 | | - # ongoing architectural work to make the message queue the sole source of |
33 | | - # search index updates. When that happens, the event_type below should |
34 | | - # be changed - perhaps to a newly introduced, more-appropriately named |
35 | | - # one. Maybe something like 'reindex'. |
| 20 | + def publish_to_queue(edition) |
| 21 | + presenter = DownstreamPayload.new(edition, version, draft: false) |
| 22 | + queue_payload = presenter.message_queue_payload |
| 23 | + service = PublishingAPI.service(:queue_publisher) |
36 | 24 |
|
37 | | - PublishingAPI.service(:queue_publisher).send_message(queue_payload, event_type: "links") |
| 25 | + # Requeue is considered a different event_type to major, minor etc |
| 26 | + # because we don't want to send additional email alerts to users. |
| 27 | + service.send_message( |
| 28 | + queue_payload, |
| 29 | + routing_key: "#{edition.schema_name}.bulk.reindex", |
| 30 | + persistent: false |
| 31 | + ) |
38 | 32 | end |
39 | 33 | end |
0 commit comments