Skip to content

Commit

Permalink
Update usage of Console logger.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Dec 9, 2024
1 parent dfd9419 commit 02f50a4
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 35 deletions.
10 changes: 5 additions & 5 deletions examples/container.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@

container = Async::Container.new

Console.logger.debug "Spawning 2 containers..."
Console.debug "Spawning 2 containers..."

2.times do
container.spawn do |task|
Console.logger.debug task, "Sleeping..."
Console.debug task, "Sleeping..."
sleep(2)
Console.logger.debug task, "Waking up!"
Console.debug task, "Waking up!"
end
end

Console.logger.debug "Waiting for container..."
Console.debug "Waiting for container..."
container.wait
Console.logger.debug "Finished."
Console.debug "Finished."
10 changes: 5 additions & 5 deletions examples/controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ class Controller < Async::Container::Controller
def setup(container)
container.run(count: 1, restart: true) do |instance|
if container.statistics.failed?
Console.logger.debug(self, "Child process restarted #{container.statistics.restarts} times.")
Console.debug(self, "Child process restarted #{container.statistics.restarts} times.")
else
Console.logger.debug(self, "Child process started.")
Console.debug(self, "Child process started.")
end

instance.ready!

while true
sleep 1

Console.logger.debug(self, "Work")
Console.debug(self, "Work")

if rand < 0.5
Console.logger.debug(self, "Should exit...")
Console.debug(self, "Should exit...")
sleep 0.5
exit(1)
end
Expand All @@ -35,7 +35,7 @@ def setup(container)

Console.logger.debug!

Console.logger.debug(self, "Starting up...")
Console.debug(self, "Starting up...")

controller = Controller.new

Expand Down
10 changes: 5 additions & 5 deletions guides/getting-started/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ Console.logger.debug!
container = Async::Container.new

container.spawn do |task|
Console.logger.debug task, "Sleeping..."
Console.debug task, "Sleeping..."
sleep(1)
Console.logger.debug task, "Waking up!"
Console.debug task, "Waking up!"
end

Console.logger.debug "Waiting for container..."
Console.debug "Waiting for container..."
container.wait
Console.logger.debug "Finished."
Console.debug "Finished."
```

## Controllers
Expand All @@ -58,7 +58,7 @@ class Controller < Async::Container::Controller
def setup(container)
container.run count: 2, restart: true do |instance|
while true
Console.logger.debug(instance, "Sleeping...")
Console.debug(instance, "Sleeping...")
sleep(1)
end
end
Expand Down
18 changes: 9 additions & 9 deletions lib/async/container/controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ def restart
if @container
@notify&.restarting!

Console.logger.debug(self) {"Restarting container..."}
Console.debug(self) {"Restarting container..."}
else
Console.logger.debug(self) {"Starting container..."}
Console.debug(self) {"Starting container..."}
end

container = self.create_container
Expand All @@ -125,9 +125,9 @@ def restart
end

# Wait for all child processes to enter the ready state.
Console.logger.debug(self, "Waiting for startup...")
Console.debug(self, "Waiting for startup...")
container.wait_until_ready
Console.logger.debug(self, "Finished startup.")
Console.debug(self, "Finished startup.")

if container.failed?
@notify&.error!("Container failed to start!")
Expand All @@ -143,7 +143,7 @@ def restart
container = nil

if old_container
Console.logger.debug(self, "Stopping old container...")
Console.debug(self, "Stopping old container...")
old_container&.stop(@graceful_stop)
end

Expand All @@ -157,7 +157,7 @@ def restart
def reload
@notify&.reloading!

Console.logger.info(self) {"Reloading container: #{@container}..."}
Console.info(self) {"Reloading container: #{@container}..."}

begin
self.setup(@container)
Expand All @@ -166,11 +166,11 @@ def reload
end

# Wait for all child processes to enter the ready state.
Console.logger.debug(self, "Waiting for startup...")
Console.debug(self, "Waiting for startup...")

@container.wait_until_ready

Console.logger.debug(self, "Finished startup.")
Console.debug(self, "Finished startup.")

if @container.failed?
@notify.error!("Container failed to reload!")
Expand Down Expand Up @@ -210,7 +210,7 @@ def run
begin
handler.call
rescue SetupError => error
Console.logger.error(self) {error}
Console.error(self) {error}
end
else
raise
Expand Down
10 changes: 5 additions & 5 deletions lib/async/container/generic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def status?(flag)
# @returns [Boolean] The children all became ready.
def wait_until_ready
while true
Console.logger.debug(self) do |buffer|
Console.debug(self) do |buffer|
buffer.puts "Waiting for ready:"
@state.each do |child, state|
buffer.puts "\t#{child.class}: #{state.inspect}"
Expand All @@ -126,7 +126,7 @@ def stop(timeout = true)
@group.stop(timeout)

if @group.running?
Console.logger.warn(self) {"Group is still running after stopping it!"}
Console.warn(self) {"Group is still running after stopping it!"}
end
ensure
@running = true
Expand All @@ -140,7 +140,7 @@ def spawn(name: nil, restart: false, key: nil, &block)
name ||= UNNAMED

if mark?(key)
Console.logger.debug(self) {"Reusing existing child for #{key}: #{name}"}
Console.debug(self) {"Reusing existing child for #{key}: #{name}"}
return false
end

Expand All @@ -161,10 +161,10 @@ def spawn(name: nil, restart: false, key: nil, &block)
end

if status.success?
Console.logger.debug(self) {"#{child} exited with #{status}"}
Console.debug(self) {"#{child} exited with #{status}"}
else
@statistics.failure!
Console.logger.error(self) {status}
Console.error(self) {status}
end

if restart
Expand Down
4 changes: 2 additions & 2 deletions lib/async/container/group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def wait
# Interrupt all running processes.
# This resumes the controlling fiber with an instance of {Interrupt}.
def interrupt
Console.logger.debug(self, "Sending interrupt to #{@running.size} running processes...")
Console.debug(self, "Sending interrupt to #{@running.size} running processes...")
@running.each_value do |fiber|
fiber.resume(Interrupt)
end
Expand All @@ -74,7 +74,7 @@ def interrupt
# Terminate all running processes.
# This resumes the controlling fiber with an instance of {Terminate}.
def terminate
Console.logger.debug(self, "Sending terminate to #{@running.size} running processes...")
Console.debug(self, "Sending terminate to #{@running.size} running processes...")
@running.each_value do |fiber|
fiber.resume(Terminate)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/async/container/notify/pipe.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def self.open!(environment = ENV)
self.new(::IO.for_fd(descriptor.to_i))
end
rescue Errno::EBADF => error
Console.logger.error(self) {error}
Console.error(self) {error}

return nil
end
Expand Down
4 changes: 2 additions & 2 deletions lib/async/container/process.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def self.fork(**options)
rescue Interrupt
# Graceful exit.
rescue Exception => error
Console.logger.error(self) {error}
Console.error(self) {error}

exit!(1)
end
Expand Down Expand Up @@ -160,7 +160,7 @@ def wait
end

if @status.nil?
Console.logger.warn(self) {"Process #{@pid} is blocking, has it exited?"}
Console.warn(self) {"Process #{@pid} is blocking, has it exited?"}
_, @status = ::Process.wait2(@pid)
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/async/container/thread.rb
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def to_s
# Invoked by the @waiter thread to indicate the outcome of the child thread.
def finished(error = nil)
if error
Console.logger.error(self) {error}
Console.error(self) {error}
end

@status = Status.new(error)
Expand Down

0 comments on commit 02f50a4

Please sign in to comment.