Created
September 4, 2022 14:41
-
-
Save thanos/605593eb6c68ddb8c0295278bced7420 to your computer and use it in GitHub Desktop.
Processing a stream in batches
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
batch_size = 100 | |
# 8 tasks running at the same time and we don't care about the results order | |
async_options = [max_concurrency: 8, ordered: false] | |
csv_rows | |
|> Stream.chunk(batch_size) | |
|> Task.async_stream(fn batch -> | |
batch | |
|> Enum.map(&CSV.generate_xml/1) | |
|> CSV.save_to_batch_rails_database() | |
end, async_options) | |
|> Stream.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment