47 lines
1.4 KiB
Ruby
47 lines
1.4 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
# ImportBotNetworkRangesJob - Background job for importing bot network ranges
|
|
#
|
|
# Imports network ranges from official bot provider sources.
|
|
# Runs asynchronously to avoid blocking the web interface.
|
|
class ImportBotNetworkRangesJob < ApplicationJob
|
|
queue_as :default
|
|
|
|
def perform(source_key, options = {})
|
|
Rails.logger.info "Starting bot network range import for source: #{source_key}"
|
|
|
|
begin
|
|
result = BotNetworkRangeImporter.import_from_source(source_key, options)
|
|
|
|
# Send notification or log completion
|
|
Rails.logger.info "Successfully imported #{result[:imported]} ranges from #{result[:source]}"
|
|
|
|
# Optionally broadcast via Turbo Streams for real-time updates
|
|
ActionCable.server.broadcast(
|
|
"bot_imports",
|
|
{
|
|
source: source_key,
|
|
status: 'completed',
|
|
imported: result[:imported],
|
|
message: "Successfully imported #{result[:imported]} ranges from #{result[:source]}"
|
|
}
|
|
)
|
|
|
|
rescue => e
|
|
Rails.logger.error "Bot network range import failed for #{source_key}: #{e.message}"
|
|
|
|
# Broadcast error notification
|
|
ActionCable.server.broadcast(
|
|
"bot_imports",
|
|
{
|
|
source: source_key,
|
|
status: 'error',
|
|
error: e.message,
|
|
message: "Failed to import from #{source_key}: #{e.message}"
|
|
}
|
|
)
|
|
|
|
raise e
|
|
end
|
|
end
|
|
end |