Skip to content

Commit 8c18ce3

Browse files
authored
chore: define inspect method for concurrent worker (#276)
1 parent 1c5e5af commit 8c18ce3

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

lib/redis_client/cluster/concurrent_worker.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
class RedisClient
88
class Cluster
99
module ConcurrentWorker
10-
InvalidNumberOfTasks = Class.new(::RedisClient::Error)
10+
InvalidNumberOfTasks = Class.new(StandardError)
1111

1212
class Group
1313
Task = Struct.new(
@@ -63,6 +63,10 @@ def close
6363
@count = 0
6464
nil
6565
end
66+
67+
def inspect
68+
"#<#{self.class.name} size: #{@count}, max: #{@size}, worker: #{@worker.class.name}>"
69+
end
6670
end
6771

6872
module_function

lib/redis_client/cluster/concurrent_worker/none.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ def push(task)
1717
end
1818

1919
def close; end
20+
21+
def inspect
22+
"#<#{self.class.name} main thread only>"
23+
end
2024
end
2125
end
2226
end

lib/redis_client/cluster/concurrent_worker/on_demand.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ def close
2626
nil
2727
end
2828

29+
def inspect
30+
"#<#{self.class.name} active: #{@q.size}, max: #{@q.max}>"
31+
end
32+
2933
private
3034

3135
def spawn_worker(task, queue)

lib/redis_client/cluster/concurrent_worker/pooled.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ def close
3838
nil
3939
end
4040

41+
def inspect
42+
"#<#{self.class.name} tasks: #{@q.size}, workers: #{@size}>"
43+
end
44+
4145
private
4246

4347
def setup
@@ -52,13 +56,15 @@ def reset
5256
end
5357

5458
def ensure_workers
55-
@workers.size.times do |i|
59+
@size.times do |i|
5660
@workers[i] = spawn_worker unless @workers[i]&.alive?
5761
end
5862
end
5963

6064
def spawn_worker
61-
Thread.new(@q) { |q| loop { q.pop.exec } }
65+
Thread.new(@q) do |q|
66+
loop { q.pop.exec }
67+
end
6268
end
6369
end
6470
end

0 commit comments

Comments
 (0)