Skip to content

Commit

Permalink
add run_worker_group callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
adamcooke committed Sep 18, 2023
1 parent 7ed3d7a commit 66513b3
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions lib/cuetip/worker_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module Cuetip
class WorkerGroup
include ActiveSupport::Callbacks

define_callbacks :run_worker_group
define_callbacks :run_worker

attr_reader :quantity
Expand Down Expand Up @@ -34,19 +35,21 @@ def start
trap('INT', &exit_trap)
trap('TERM', &exit_trap)

@quantity.times do |i|
@workers[i] = Worker.new(self, i, @queues)
Klogger.tagged worker_index: i do
Cuetip.logger.info "Starting worker"
@threads[i] = Thread.new(@workers[i]) do |worker|
run_callbacks :run_worker do
worker.run
run_callbacks :run_worker_group do
@quantity.times do |i|
@workers[i] = Worker.new(self, i, @queues)
Klogger.tagged worker_index: i do
Cuetip.logger.info "Starting worker"
@threads[i] = Thread.new(@workers[i]) do |worker|
run_callbacks :run_worker do
worker.run
end
end
end
@threads[i].abort_on_exception = true
end
@threads[i].abort_on_exception = true
@threads.values.each(&:join)
end
@threads.values.each(&:join)
end
end

Expand Down

0 comments on commit 66513b3

Please sign in to comment.