Add ChatChannels::IndexingJob (#4317) [ci skip]
This commit is contained in:
parent
daff71321f
commit
7de692156c
3 changed files with 50 additions and 1 deletions
14
app/jobs/chat_channels/index_job.rb
Normal file
14
app/jobs/chat_channels/index_job.rb
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module ChatChannels
|
||||
class IndexJob < ApplicationJob
|
||||
queue_as :chat_channels_index
|
||||
|
||||
def perform(chat_channel_id:)
|
||||
chat_channel = ChatChannel.find_by(id: chat_channel_id)
|
||||
return unless chat_channel
|
||||
|
||||
chat_channel.index!
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -37,7 +37,8 @@ class Message < ApplicationRecord
|
|||
chat_channel.touch(:last_message_at)
|
||||
chat_channel.index!
|
||||
chat_channel.chat_channel_memberships.reindex!
|
||||
chat_channel.delay.index!
|
||||
|
||||
ChatChannels::IndexJob.perform_later(chat_channel_id: chat_channel.id)
|
||||
end
|
||||
|
||||
def update_all_has_unopened_messages_statuses
|
||||
|
|
|
|||
34
spec/jobs/chat_channels/index_job_spec.rb
Normal file
34
spec/jobs/chat_channels/index_job_spec.rb
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require "rails_helper"
|
||||
|
||||
RSpec.describe ChatChannels::IndexJob, type: :job do
|
||||
include_examples "#enqueues_job", "chat_channels_index", chat_channel_id: 1
|
||||
|
||||
describe "#perform_now" do
|
||||
let(:chat_channel) { double }
|
||||
let(:chat_channel_id) { 1 }
|
||||
|
||||
context "when chat_channel is found" do
|
||||
before do
|
||||
allow(ChatChannel).to receive(:find_by).with(id: chat_channel_id).and_return(chat_channel)
|
||||
allow(chat_channel).to receive(:index!)
|
||||
end
|
||||
|
||||
it "calls index" do
|
||||
described_class.perform_now(chat_channel_id: chat_channel_id)
|
||||
expect(chat_channel).to have_received(:index!)
|
||||
end
|
||||
end
|
||||
|
||||
context "when chat_channel is not found" do
|
||||
before do
|
||||
allow(ChatChannel).to receive(:find_by).with(id: chat_channel_id).and_return(nil)
|
||||
end
|
||||
|
||||
it "doesn't fail" do
|
||||
described_class.perform_now(chat_channel_id: chat_channel_id)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Reference in a new issue