Sha256: a6c1f6d82644548d09aa3152317882d04b35d88136cd2f2a96c21e432ceac319
Contents?: true
Size: 1.39 KB
Versions: 8
Compression:
Stored size: 1.39 KB
Contents
#!/usr/bin/env ruby require 'concurrent' require 'stepmod/utils/stepmod_file_annotator' stepmod_dir = ARGV.first || Dir.pwd # build resource_docs cache resource_docs_cache_file = `mktemp` `"#{File.join(__dir__, 'stepmod-build-resource-docs-cache')}" "#{stepmod_dir}" > "#{resource_docs_cache_file}"` # annotate each file files = `"#{File.join(__dir__, 'stepmod-find-express-files')}" "#{stepmod_dir}"`.strip.split("\n") MAX_THREADS = [2, Concurrent.processor_count].max * 2 MAX_QUEUE_SIZE = MAX_THREADS * 4 # https://github.com/ruby-concurrency/concurrent-ruby/blob/master/docs-source/thread_pools.md pool = Concurrent::ThreadPoolExecutor.new( :min_threads => MAX_THREADS, :max_threads => MAX_THREADS, :max_queue => MAX_QUEUE_SIZE, :fallback_policy => :caller_runs ) files.each_slice(MAX_QUEUE_SIZE) do |batch| puts("Queueing next batch") batch.each do |file| pool.post do puts("#{Thread.current.object_id}: Queued processing #{file}") annotated = Stepmod::Utils::StepmodFileAnnotator.new(express_file: file, resource_docs_cache_file: resource_docs_cache_file, stepmod_dir: stepmod_dir).call File.open(File.join(File.dirname(file), "#{File.basename(file, '.exp')}_annotated.exp"), 'w') do |file| file.puts(annotated) end puts("#{Thread.current.object_id}: Done processing #{file}") end end pool.shutdown end # cleanup `rm "#{resource_docs_cache_file}"`
Version data entries
8 entries across 8 versions & 1 rubygems