File tree 1 file changed +3
-18
lines changed
1 file changed +3
-18
lines changed Original file line number Diff line number Diff line change 3
3
module Webhooks
4
4
# The class sends events in multi-threaded mode
5
5
class Sender
6
- MAX_THREADS = 8
6
+ BATCH_SIZE = 8
7
7
URL = Settings . webhooks_url
8
8
9
9
def initialize ( events )
@@ -14,9 +14,9 @@ def initialize(events)
14
14
def send_events
15
15
return unless URL
16
16
17
- sort_events . each_value do |events |
17
+ events . compact . each_slice ( BATCH_SIZE ) do |events_batch |
18
18
thread = Thread . new do
19
- events . each do |event |
19
+ events_batch . each do |event |
20
20
Client . new ( URL ) . send_payload ( event )
21
21
end
22
22
end
@@ -30,20 +30,5 @@ def send_events
30
30
private
31
31
32
32
attr_reader :events , :threads
33
-
34
- def sort_events
35
- i = 1
36
- result = { }
37
-
38
- events . compact . each do |event |
39
- arr = result [ i ]
40
- arr = [ ] if arr . nil?
41
- arr << event
42
- result [ i ] = arr
43
- i >= MAX_THREADS ? i = 1 : i += 1
44
- end
45
-
46
- result
47
- end
48
33
end
49
34
end
You can’t perform that action at this time.
0 commit comments