Skip to content

Commit d06363f

Browse files
committed
Refactor Async.logger -> Console.logger.
1 parent c8de345 commit d06363f

File tree

8 files changed

+32
-34
lines changed

8 files changed

+32
-34
lines changed

examples/container.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
require '../lib/async/container/controller'
55
require '../lib/async/container/forked'
66

7-
Async.logger.debug!
7+
Console.logger.debug!
88

9-
Async.logger.debug(self, "Starting up...")
9+
Console.logger.debug(self, "Starting up...")
1010

1111
controller = Async::Container::Controller.new do |container|
12-
Async.logger.debug(self, "Setting up container...")
12+
Console.logger.debug(self, "Setting up container...")
1313

1414
container.run(count: 1, restart: true) do
15-
Async.logger.debug(self, "Child process started.")
15+
Console.logger.debug(self, "Child process started.")
1616

1717
while true
1818
sleep 1
@@ -22,12 +22,12 @@
2222
end
2323
end
2424
ensure
25-
Async.logger.debug(self, "Child process exiting:", $!)
25+
Console.logger.debug(self, "Child process exiting:", $!)
2626
end
2727
end
2828

2929
begin
3030
controller.run
3131
ensure
32-
Async.logger.debug(controller, "Parent process exiting:", $!)
32+
Console.logger.debug(controller, "Parent process exiting:", $!)
3333
end

guides/getting-started/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ A container represents a set of child processes (or threads) which are doing wor
2424
``` ruby
2525
require 'async/container'
2626

27-
Async.logger.debug!
27+
Console.logger.debug!
2828

2929
container = Async::Container.new
3030

@@ -34,9 +34,9 @@ container.async do |task|
3434
task.logger.debug "Waking up!"
3535
end
3636

37-
Async.logger.debug "Waiting for container..."
37+
Console.logger.debug "Waiting for container..."
3838
container.wait
39-
Async.logger.debug "Finished."
39+
Console.logger.debug "Finished."
4040
```
4141

4242
## Controllers
@@ -46,13 +46,13 @@ The controller provides the life-cycle management for one or more containers of
4646
``` ruby
4747
require 'async/container'
4848

49-
Async.logger.debug!
49+
Console.logger.debug!
5050

5151
class Controller < Async::Container::Controller
5252
def setup(container)
5353
container.async do |task|
5454
while true
55-
Async.logger.debug("Sleeping...")
55+
Console.logger.debug("Sleeping...")
5656
task.sleep(1)
5757
end
5858
end

lib/async/container/controller.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,9 @@ def restart
122122
if @container
123123
@notify&.restarting!
124124

125-
Async.logger.debug(self) {"Restarting container..."}
125+
Console.logger.debug(self) {"Restarting container..."}
126126
else
127-
Async.logger.debug(self) {"Starting container..."}
127+
Console.logger.debug(self) {"Starting container..."}
128128
end
129129

130130
container = self.create_container
@@ -138,9 +138,9 @@ def restart
138138
end
139139

140140
# Wait for all child processes to enter the ready state.
141-
Async.logger.debug(self, "Waiting for startup...")
141+
Console.logger.debug(self, "Waiting for startup...")
142142
container.wait_until_ready
143-
Async.logger.debug(self, "Finished startup.")
143+
Console.logger.debug(self, "Finished startup.")
144144

145145
if container.failed?
146146
@notify&.error!($!.to_s)
@@ -154,7 +154,7 @@ def restart
154154
old_container = @container
155155
@container = container
156156

157-
Async.logger.debug(self, "Stopping old container...")
157+
Console.logger.debug(self, "Stopping old container...")
158158
old_container&.stop
159159
@notify&.ready!
160160
rescue
@@ -168,7 +168,7 @@ def restart
168168
def reload
169169
@notify&.reloading!
170170

171-
Async.logger.info(self) {"Reloading container: #{@container}..."}
171+
Console.logger.info(self) {"Reloading container: #{@container}..."}
172172

173173
begin
174174
self.setup(@container)
@@ -177,9 +177,9 @@ def reload
177177
end
178178

179179
# Wait for all child processes to enter the ready state.
180-
Async.logger.debug(self, "Waiting for startup...")
180+
Console.logger.debug(self, "Waiting for startup...")
181181
@container.wait_until_ready
182-
Async.logger.debug(self, "Finished startup.")
182+
Console.logger.debug(self, "Finished startup.")
183183

184184
if @container.failed?
185185
@notify.error!("Container failed!")
@@ -215,7 +215,7 @@ def run
215215
begin
216216
handler.call
217217
rescue SetupError => error
218-
Async.logger.error(self) {error}
218+
Console.logger.error(self) {error}
219219
end
220220
else
221221
raise

lib/async/container/generic.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def status?(flag)
119119
# @returns [Boolean] The children all became ready.
120120
def wait_until_ready
121121
while true
122-
Async.logger.debug(self) do |buffer|
122+
Console.logger.debug(self) do |buffer|
123123
buffer.puts "Waiting for ready:"
124124
@state.each do |child, state|
125125
buffer.puts "\t#{child.class}: #{state.inspect}"
@@ -141,7 +141,7 @@ def stop(timeout = true)
141141
@group.stop(timeout)
142142

143143
if @group.running?
144-
Async.logger.warn(self) {"Group is still running after stopping it!"}
144+
Console.logger.warn(self) {"Group is still running after stopping it!"}
145145
end
146146
ensure
147147
@running = true
@@ -155,7 +155,7 @@ def spawn(name: nil, restart: false, key: nil, &block)
155155
name ||= UNNAMED
156156

157157
if mark?(key)
158-
Async.logger.debug(self) {"Reusing existing child for #{key}: #{name}"}
158+
Console.logger.debug(self) {"Reusing existing child for #{key}: #{name}"}
159159
return false
160160
end
161161

@@ -176,10 +176,10 @@ def spawn(name: nil, restart: false, key: nil, &block)
176176
end
177177

178178
if status.success?
179-
Async.logger.info(self) {"#{child} exited with #{status}"}
179+
Console.logger.info(self) {"#{child} exited with #{status}"}
180180
else
181181
@statistics.failure!
182-
Async.logger.error(self) {status}
182+
Console.logger.error(self) {status}
183183
end
184184

185185
if restart
@@ -189,7 +189,7 @@ def spawn(name: nil, restart: false, key: nil, &block)
189189
end
190190
end
191191
# ensure
192-
# Async.logger.error(self) {$!} if $!
192+
# Console.logger.error(self) {$!} if $!
193193
end.resume
194194

195195
return true

lib/async/container/group.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def wait
7878
# Interrupt all running processes.
7979
# This resumes the controlling fiber with an instance of {Interrupt}.
8080
def interrupt
81-
Async.logger.debug(self, "Sending interrupt to #{@running.size} running processes...")
81+
Console.logger.debug(self, "Sending interrupt to #{@running.size} running processes...")
8282
@running.each_value do |fiber|
8383
fiber.resume(Interrupt)
8484
end
@@ -87,7 +87,7 @@ def interrupt
8787
# Terminate all running processes.
8888
# This resumes the controlling fiber with an instance of {Terminate}.
8989
def terminate
90-
Async.logger.debug(self, "Sending terminate to #{@running.size} running processes...")
90+
Console.logger.debug(self, "Sending terminate to #{@running.size} running processes...")
9191
@running.each_value do |fiber|
9292
fiber.resume(Terminate)
9393
end

lib/async/container/notify/pipe.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def self.open!(environment = ENV)
3838
self.new(::IO.for_fd(descriptor.to_i))
3939
end
4040
rescue Errno::EBADF => error
41-
Async.logger.error(self) {error}
41+
Console.logger.error(self) {error}
4242

4343
return nil
4444
end

lib/async/container/process.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def self.fork(**options)
9191
rescue Interrupt
9292
# Graceful exit.
9393
rescue Exception => error
94-
Async.logger.error(self) {error}
94+
Console.logger.error(self) {error}
9595

9696
exit!(1)
9797
end
@@ -177,7 +177,7 @@ def wait
177177
end
178178

179179
if @status.nil?
180-
Async.logger.warn(self) {"Process #{@pid} is blocking, has it exited?"}
180+
Console.logger.warn(self) {"Process #{@pid} is blocking, has it exited?"}
181181
_, @status = ::Process.wait2(@pid)
182182
end
183183
end

lib/async/container/thread.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
require_relative 'error'
2525
require_relative 'notify/pipe'
2626

27-
require 'async/logger'
28-
2927
module Async
3028
module Container
3129
# Represents a running child thread from the point of view of the parent container.
@@ -207,7 +205,7 @@ def to_s
207205
# Invoked by the @waiter thread to indicate the outcome of the child thread.
208206
def finished(error = nil)
209207
if error
210-
Async.logger.error(self) {error}
208+
Console.logger.error(self) {error}
211209
end
212210

213211
@status = Status.new(error)

0 commit comments

Comments
 (0)