lib/nanoc/base/services/compiler/phases/write.rb in nanoc-4.11.0 vs lib/nanoc/base/services/compiler/phases/write.rb in nanoc-4.11.1
- old
+ new
@@ -1,77 +1,83 @@
# frozen_string_literal: true
-module Nanoc::Int::Compiler::Phases
- class Write < Abstract
- include Nanoc::Int::ContractsSupport
+module Nanoc
+ module Int
+ class Compiler
+ module Phases
+ class Write < Abstract
+ include Nanoc::Core::ContractsSupport
- class Worker
- def initialize(queue:, snapshot_repo:)
- @queue = queue
- @snapshot_repo = snapshot_repo
- end
+ class Worker
+ def initialize(queue:, compiled_content_store:)
+ @queue = queue
+ @compiled_content_store = compiled_content_store
+ end
- def start
- @thread = Thread.new do
- Thread.current.abort_on_exception = true
- Thread.current.priority = -1 # schedule I/O work ASAP
+ def start
+ @thread = Thread.new do
+ Thread.current.abort_on_exception = true
+ Thread.current.priority = -1 # schedule I/O work ASAP
- writer = Nanoc::Int::ItemRepWriter.new
+ writer = Nanoc::Int::ItemRepWriter.new
- while rep = @queue.pop # rubocop:disable Lint/AssignmentInCondition
- writer.write_all(rep, @snapshot_repo)
+ while rep = @queue.pop # rubocop:disable Lint/AssignmentInCondition
+ writer.write_all(rep, @compiled_content_store)
+ end
+ end
+ end
+
+ def join
+ @thread.join
+ end
end
- end
- end
- def join
- @thread.join
- end
- end
+ class WorkerPool
+ def initialize(queue:, size:, compiled_content_store:)
+ @workers = Array.new(size) { Worker.new(queue: queue, compiled_content_store: compiled_content_store) }
+ end
- class WorkerPool
- def initialize(queue:, size:, snapshot_repo:)
- @workers = Array.new(size) { Worker.new(queue: queue, snapshot_repo: snapshot_repo) }
- end
+ def start
+ @workers.each(&:start)
+ end
- def start
- @workers.each(&:start)
- end
+ def join
+ @workers.each(&:join)
+ end
+ end
- def join
- @workers.each(&:join)
- end
- end
+ QUEUE_SIZE = 40
+ WORKER_POOL_SIZE = 5
- QUEUE_SIZE = 40
- WORKER_POOL_SIZE = 5
+ def initialize(compiled_content_store:, wrapped:)
+ super(wrapped: wrapped)
- def initialize(snapshot_repo:, wrapped:)
- super(wrapped: wrapped)
+ @compiled_content_store = compiled_content_store
- @snapshot_repo = snapshot_repo
+ @queue = SizedQueue.new(QUEUE_SIZE)
+ @worker_pool = WorkerPool.new(queue: @queue, size: WORKER_POOL_SIZE, compiled_content_store: @compiled_content_store)
+ end
- @queue = SizedQueue.new(QUEUE_SIZE)
- @worker_pool = WorkerPool.new(queue: @queue, size: WORKER_POOL_SIZE, snapshot_repo: @snapshot_repo)
- end
+ def start
+ super
+ @worker_pool.start
+ end
- def start
- super
- @worker_pool.start
- end
+ def stop
+ super
+ @queue.close
+ @worker_pool.join
+ end
- def stop
- super
- @queue.close
- @worker_pool.join
- end
+ contract Nanoc::Core::ItemRep, C::KeywordArgs[is_outdated: C::Bool], C::Func[C::None => C::Any] => C::Any
+ def run(rep, is_outdated:) # rubocop:disable Lint/UnusedMethodArgument
+ yield
- contract Nanoc::Int::ItemRep, C::KeywordArgs[is_outdated: C::Bool], C::Func[C::None => C::Any] => C::Any
- def run(rep, is_outdated:) # rubocop:disable Lint/UnusedMethodArgument
- yield
+ @queue << rep
- @queue << rep
-
- Nanoc::Int::NotificationCenter.post(:rep_write_enqueued, rep)
+ Nanoc::Core::NotificationCenter.post(:rep_write_enqueued, rep)
+ end
+ end
+ end
end
end
end