discourse/plugins/chat/app/jobs/regular/chat_channel_archive.rb
Roman Rizzi 0a5f548635
DEV: Move discourse-chat to the core repo. (#18776)
As part of this move, we are also renaming `discourse-chat` to `chat`.
2022-11-02 10:41:30 -03:00

27 lines
789 B
Ruby

# frozen_string_literal: true
module Jobs
class ChatChannelArchive < ::Jobs::Base
sidekiq_options retry: false
def execute(args = {})
channel_archive = ::ChatChannelArchive.find_by(id: args[:chat_channel_archive_id])
# this should not really happen, but better to do this than throw an error
if channel_archive.blank?
Rails.logger.warn(
"Chat channel archive #{args[:chat_channel_archive_id]} could not be found, aborting archive job.",
)
return
end
return if channel_archive.complete?
DistributedMutex.synchronize(
"archive_chat_channel_#{channel_archive.chat_channel_id}",
validity: 20.minutes,
) { Chat::ChatChannelArchiveService.new(channel_archive).execute }
end
end
end