Skip to content

Commit

Permalink
init b
Browse files Browse the repository at this point in the history
  • Loading branch information
leonovk committed Aug 20, 2024
1 parent 2c7ceaa commit 1ebf144
Showing 1 changed file with 3 additions and 18 deletions.
21 changes: 3 additions & 18 deletions lib/webhooks/sender.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Webhooks
# The class sends events in multi-threaded mode
class Sender
MAX_THREADS = 8
BATCH_SIZE = 8
URL = Settings.webhooks_url

def initialize(events)
Expand All @@ -14,9 +14,9 @@ def initialize(events)
def send_events
return unless URL

sort_events.each_value do |events|
events.compact.each_slice(BATCH_SIZE) do |events_batch|
thread = Thread.new do
events.each do |event|
events_batch.each do |event|
Client.new(URL).send_payload(event)
end
end
Expand All @@ -30,20 +30,5 @@ def send_events
private

attr_reader :events, :threads

def sort_events
i = 1
result = {}

events.compact.each do |event|
arr = result[i]
arr = [] if arr.nil?
arr << event
result[i] = arr
i >= MAX_THREADS ? i = 1 : i += 1
end

result
end
end
end

0 comments on commit 1ebf144

Please sign in to comment.