-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1503 from senid231/1482-pgq-cdr-http-batch
add CdrHttpBatch PGQ Processor, add data filters to CdrHttp/CdrHttpBatch PGQ Processors
- Loading branch information
Showing
8 changed files
with
952 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
# frozen_string_literal: true | ||
|
||
class EventFilter | ||
OPERATORS = %i[ | ||
eq not_eq | ||
start_with end_with contains | ||
gt lt gte lte | ||
in not_in | ||
null not_null | ||
true false | ||
].freeze | ||
|
||
attr_reader :field, :op, :value | ||
|
||
def initialize(field:, op:, value:) | ||
@field = field.to_s | ||
@op = op.to_sym | ||
raise ArgumentError, "Invalid operator: #{@op}" unless OPERATORS.include?(@op) | ||
|
||
@value = value | ||
end | ||
|
||
def match?(event) | ||
send("match_#{op}?", event.transform_keys(&:to_s)) | ||
end | ||
|
||
private | ||
|
||
def match_eq?(event) | ||
event[field] == value | ||
end | ||
|
||
def match_not_eq?(event) | ||
event[field] != value | ||
end | ||
|
||
def match_start_with?(event) | ||
event[field].to_s.start_with?(value.to_s) | ||
end | ||
|
||
def match_end_with?(event) | ||
event[field].to_s.end_with?(value.to_s) | ||
end | ||
|
||
def match_contains?(event) | ||
event[field].to_s.include?(value.to_s) | ||
end | ||
|
||
def match_gt?(event) | ||
!event[field].nil? && event[field] > value | ||
end | ||
|
||
def match_lt?(event) | ||
!event[field].nil? && event[field] < value | ||
end | ||
|
||
def match_gte?(event) | ||
!event[field].nil? && event[field] >= value | ||
end | ||
|
||
def match_lte?(event) | ||
!event[field].nil? && event[field] <= value | ||
end | ||
|
||
def match_in?(event) | ||
value.include?(event[field]) | ||
end | ||
|
||
def match_not_in?(event) | ||
value.exclude?(event[field]) | ||
end | ||
|
||
def match_null?(event) | ||
event[field].nil? | ||
end | ||
|
||
def match_not_null?(event) | ||
!event[field].nil? | ||
end | ||
|
||
def match_true?(event) | ||
event[field] == true | ||
end | ||
|
||
def match_false?(event) | ||
event[field] == false | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rest-client' | ||
require_relative 'cdr_http_base' | ||
|
||
class CdrHttpBatch < CdrHttpBase | ||
@consumer_name = 'cdr_http' | ||
|
||
def perform_group(events) | ||
events_to_send = events.select { |event| send_event?(event) } | ||
return if events_to_send.empty? | ||
|
||
permitted_events = events_to_send.map { |event| permit_field_for(event) } | ||
perform_http_request(permitted_events) | ||
end | ||
|
||
private | ||
|
||
def http_body(events) | ||
{ data: events }.to_json | ||
end | ||
end |
Oops, something went wrong.