Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adds some threads #3

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env-example
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ WEBLOGIN_SECRET=your-weblogin-secret
WEBLOGIN_ID=your-weblogin-id'
WEBLOGIN_ON=true
CATALOG_SOLR=http://url-to-solr/solr/biblio
MAX_THREADS=5
23 changes: 16 additions & 7 deletions lib/report_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,31 @@ class ReportGenerator
def initialize(barcodes: [])
@barcodes = barcodes
@umich_catalog_items = UmichCatalogItems.for(barcodes: @barcodes)
Logger.new($stdout).info("fetched umich catalog items")
end

def run
queue = Queue.new
queue.push(header_row)

@barcodes.each do |barcode|
umich_item = @umich_catalog_items.item_for_barcode(barcode)
next if umich_item.nil?
worldcat_summary = WorldCatSummary.for(umich_item.oclc || [])
barcode_queue = @barcodes.inject(Queue.new, :push)

queue.push(
format_line(umich_item: umich_item, worldcat_summary: worldcat_summary)
)
threads = Array.new(ENV.fetch(MAX_THREADS)) do
Thread.new do
until barcode_queue.empty?
barcode = barcode_queue.shift
umich_item = @umich_catalog_items.item_for_barcode(barcode)
next if umich_item.nil?
worldcat_summary = WorldCatSummary.for(umich_item.oclc || [])

queue.push(
format_line(umich_item: umich_item, worldcat_summary: worldcat_summary)
)
end
end
end

threads.each(&:join)
print(queue)
end

Expand Down