Sha256: 7c9fceafea3d761b97d6ce2472f536f0a3184eead375d93684052d7cf6c8fe37
Contents?: true
Size: 1.5 KB
Versions: 10
Compression:
Stored size: 1.5 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
10 entries across 10 versions & 1 rubygems