-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make page batch jobs nested classes of their counterparts
- Loading branch information
Showing
15 changed files
with
120 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,19 @@ | ||
module Pages | ||
class RefreshSearchIndexJob < ApplicationJob | ||
def perform | ||
Page.published.find_each(&:update_in_search_index) | ||
class Batch < ApplicationJob | ||
queue_as :default | ||
|
||
def perform | ||
Page.published.find_each do |page| | ||
Pages::RefreshSearchIndexJob.perform_later(page) | ||
end | ||
end | ||
end | ||
|
||
queue_as :default | ||
|
||
def perform(page) | ||
page.update_in_search_index | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,24 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe Pages::RefreshSearchIndexJob, type: :job do | ||
it "doesn’t blow up when indexing the current pages" do | ||
Page.upsert_collection_from_sitepress! | ||
describe Pages::RefreshSearchIndexJob::Batch do | ||
it "doesn’t blow up when indexing the current pages" do | ||
Page.upsert_collection_from_sitepress! | ||
perform_enqueued_jobs | ||
|
||
expect { described_class.perform_now }.not_to raise_error | ||
end | ||
expect { Pages::RefreshSearchIndexJob::Batch.perform_now }.not_to raise_error | ||
end | ||
|
||
it "indexes the right stuff" do | ||
page_1 = FactoryBot.create(:page, :published, request_path: "/articles/introducing-joy-of-rails") | ||
page_2 = FactoryBot.create(:page, :published, request_path: "/articles/custom-color-schemes-with-ruby-on-rails") | ||
page_3 = FactoryBot.create(:page, :unpublished, request_path: "/articles/joy-of-rails-2") | ||
it "indexes the right stuff" do | ||
page_1 = FactoryBot.create(:page, :published, request_path: "/articles/introducing-joy-of-rails") | ||
page_2 = FactoryBot.create(:page, :published, request_path: "/articles/custom-color-schemes-with-ruby-on-rails") | ||
page_3 = FactoryBot.create(:page, :unpublished, request_path: "/articles/joy-of-rails-2") | ||
|
||
described_class.perform_now | ||
Pages::RefreshSearchIndexJob::Batch.perform_now | ||
perform_enqueued_jobs | ||
|
||
expect(Page.join_search_index).to include(page_1, page_2) | ||
expect(Page.join_search_index).not_to include(page_3) | ||
expect(Page.join_search_index).to include(page_1, page_2) | ||
expect(Page.join_search_index).not_to include(page_3) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters