Many updates
This commit is contained in:
@@ -9,9 +9,8 @@ class ProcessWafPoliciesJob < ApplicationJob
|
||||
|
||||
retry_on StandardError, wait: 5.seconds, attempts: 3
|
||||
|
||||
def perform(network_range_id:, event_id: nil)
|
||||
# Find the network range
|
||||
network_range = NetworkRange.find_by(id: network_range_id)
|
||||
def perform(network_range:, event: nil)
|
||||
# network_range and event are passed as Global IDs and automatically deserialized
|
||||
return if network_range.nil?
|
||||
|
||||
Rails.logger.debug "Processing WAF policies for network range #{network_range.cidr}"
|
||||
@@ -55,36 +54,32 @@ class ProcessWafPoliciesJob < ApplicationJob
|
||||
network_range.update_column(:policies_evaluated_at, Time.current)
|
||||
|
||||
# Update event record if provided
|
||||
if event_id.present?
|
||||
event = Event.find_by(id: event_id)
|
||||
if event.present?
|
||||
# Add policy match information to event metadata
|
||||
# Handle potential nil payload or type issues
|
||||
current_payload = event.payload || {}
|
||||
if event.present?
|
||||
# Add policy match information to event metadata
|
||||
# Handle potential nil payload or type issues
|
||||
current_payload = event.payload || {}
|
||||
|
||||
# Ensure payload is a hash before merging
|
||||
unless current_payload.is_a?(Hash)
|
||||
Rails.logger.warn "Event #{event_id} has invalid payload type: #{current_payload.class}, resetting to hash"
|
||||
current_payload = {}
|
||||
end
|
||||
|
||||
event.update!(payload: current_payload.merge({
|
||||
policy_matches: {
|
||||
matching_policies_count: result[:matching_policies].length,
|
||||
generated_rules_count: result[:generated_rules].length,
|
||||
processed_at: Time.current.iso8601
|
||||
}
|
||||
}))
|
||||
else
|
||||
Rails.logger.warn "Event #{event_id} not found for ProcessWafPoliciesJob, skipping update"
|
||||
# Ensure payload is a hash before merging
|
||||
unless current_payload.is_a?(Hash)
|
||||
Rails.logger.warn "Event #{event.id} has invalid payload type: #{current_payload.class}, resetting to hash"
|
||||
current_payload = {}
|
||||
end
|
||||
|
||||
event.update!(payload: current_payload.merge({
|
||||
policy_matches: {
|
||||
matching_policies_count: result[:matching_policies].length,
|
||||
generated_rules_count: result[:generated_rules].length,
|
||||
processed_at: Time.current.iso8601
|
||||
}
|
||||
}))
|
||||
end
|
||||
end
|
||||
|
||||
# Class method for batch processing multiple network ranges
|
||||
def self.process_network_ranges(network_range_ids)
|
||||
network_range_ids.each do |network_range_id|
|
||||
perform_later(network_range_id: network_range_id)
|
||||
network_range = NetworkRange.find_by(id: network_range_id)
|
||||
perform_later(network_range: network_range) if network_range
|
||||
end
|
||||
end
|
||||
|
||||
@@ -109,7 +104,7 @@ class ProcessWafPoliciesJob < ApplicationJob
|
||||
Rails.logger.info "Reprocessing #{network_ranges.count} network ranges for policy #{waf_policy_id}"
|
||||
|
||||
network_ranges.find_each do |network_range|
|
||||
perform_later(network_range_id: network_range.id)
|
||||
perform_later(network_range: network_range)
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user