Skip to content

Commit

Permalink
feat: randomize batch size
Browse files Browse the repository at this point in the history
  • Loading branch information
Ziinc committed Jan 25, 2024
1 parent 1e4023a commit 6deede4
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/pipeline.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,15 @@ defmodule Loadfest.Pipeline do
end

def handle_demand(demand, state) when demand > 0 do
messages = for _i <- 1..demand do
%Broadway.Message{data: Loadfest.Worker.make_batch(250), acknowledger: {__MODULE__, :ack, 3}}
end
num = Enum.random([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 50, 50, 50, 250])

messages =
for _i <- 1..demand do
%Broadway.Message{
data: Loadfest.Worker.make_batch(num),
acknowledger: {__MODULE__, :ack, 3}
}
end

{:noreply, messages, state}
end
Expand Down

0 comments on commit 6deede4

Please sign in to comment.