-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved logging when child process fails.
- Loading branch information
Showing
9 changed files
with
197 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/usr/bin/env ruby | ||
# frozen_string_literal: true | ||
|
||
require "console" | ||
require "async/container/notify" | ||
|
||
# Console.logger.debug! | ||
|
||
class Jobs | ||
def self.start = self.new.start | ||
|
||
def start | ||
Console.info(self, "Starting jobs...") | ||
|
||
if notify = Async::Container::Notify.open! | ||
Console.info(self, "Notifying container ready...") | ||
notify.ready! | ||
end | ||
|
||
loop do | ||
Console.info(self, "Jobs running...") | ||
|
||
sleep 10 | ||
end | ||
rescue Interrupt | ||
Console.info(self, "Exiting jobs...") | ||
end | ||
end | ||
|
||
Jobs.start |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# Exec Child Example | ||
|
||
This example demonstrates how to execute a child process using the `exec` function in a container. | ||
|
||
## Usage | ||
|
||
Start the main controller: | ||
|
||
``` | ||
> bundle exec ./start | ||
0.0s info: AppController [oid=0x938] [ec=0x94c] [pid=96758] [2024-12-12 14:33:45 +1300] | ||
| Controller starting... | ||
0.65s info: Jobs [oid=0x8e8] [ec=0x8fc] [pid=96763] [2024-12-12 14:33:45 +1300] | ||
| Starting jobs... | ||
0.65s info: Jobs [oid=0x8e8] [ec=0x8fc] [pid=96763] [2024-12-12 14:33:45 +1300] | ||
| Notifying container ready... | ||
0.65s info: Jobs [oid=0x8e8] [ec=0x8fc] [pid=96763] [2024-12-12 14:33:45 +1300] | ||
| Jobs running... | ||
0.65s info: Web [oid=0x8e8] [ec=0x8fc] [pid=96760] [2024-12-12 14:33:45 +1300] | ||
| Starting web... | ||
0.65s info: Web [oid=0x8e8] [ec=0x8fc] [pid=96760] [2024-12-12 14:33:45 +1300] | ||
| Notifying container ready... | ||
0.65s info: Web [oid=0x8e8] [ec=0x8fc] [pid=96760] [2024-12-12 14:33:45 +1300] | ||
| Web running... | ||
0.09s info: AppController [oid=0x938] [ec=0x94c] [pid=96758] [2024-12-12 14:33:45 +1300] | ||
| Controller started... | ||
``` | ||
|
||
In another terminal: `kill -HUP 96758` to cause a blue-green restart, which causes a new container to be started with new jobs and web processes: | ||
|
||
``` | ||
9.57s info: Jobs [oid=0x8e8] [ec=0x8fc] [pid=96836] [2024-12-12 14:33:54 +1300] | ||
| Starting jobs... | ||
9.57s info: Web [oid=0x8e8] [ec=0x8fc] [pid=96833] [2024-12-12 14:33:54 +1300] | ||
| Starting web... | ||
9.57s info: Jobs [oid=0x8e8] [ec=0x8fc] [pid=96836] [2024-12-12 14:33:54 +1300] | ||
| Notifying container ready... | ||
9.57s info: Web [oid=0x8e8] [ec=0x8fc] [pid=96833] [2024-12-12 14:33:54 +1300] | ||
| Notifying container ready... | ||
9.57s info: Jobs [oid=0x8e8] [ec=0x8fc] [pid=96836] [2024-12-12 14:33:54 +1300] | ||
| Jobs running... | ||
9.57s info: Web [oid=0x8e8] [ec=0x8fc] [pid=96833] [2024-12-12 14:33:54 +1300] | ||
| Web running... | ||
``` | ||
|
||
Once the new container is running and the child processes have notified they are ready, the controller will stop the old container: | ||
|
||
``` | ||
9.01s info: Async::Container::Group [oid=0xa00] [ec=0x94c] [pid=96758] [2024-12-12 14:33:54 +1300] | ||
| Stopping all processes... | ||
| { | ||
| "timeout": true | ||
| } | ||
9.01s info: Async::Container::Group [oid=0xa00] [ec=0x94c] [pid=96758] [2024-12-12 14:33:54 +1300] | ||
| Sending interrupt to 2 running processes... | ||
9.57s info: Web [oid=0x8e8] [ec=0x8fc] [pid=96760] [2024-12-12 14:33:54 +1300] | ||
| Exiting web... | ||
9.57s info: Jobs [oid=0x8e8] [ec=0x8fc] [pid=96763] [2024-12-12 14:33:54 +1300] | ||
| Exiting jobs... | ||
``` | ||
|
||
The new container continues to run as expected: | ||
|
||
``` | ||
19.57s info: Web [oid=0x8e8] [ec=0x8fc] [pid=96833] [2024-12-12 14:34:04 +1300] | ||
| Web running... | ||
19.57s info: Jobs [oid=0x8e8] [ec=0x8fc] [pid=96836] [2024-12-12 14:34:04 +1300] | ||
| Jobs running... | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/usr/bin/env ruby | ||
# frozen_string_literal: true | ||
|
||
require "async/container" | ||
require "console" | ||
|
||
# Console.logger.debug! | ||
|
||
class AppController < Async::Container::Controller | ||
def setup(container) | ||
container.spawn(name: "Web") do |instance| | ||
# Specify ready: false here as the child process is expected to take care of the readiness notification: | ||
instance.exec("bundle", "exec", "web", ready: false) | ||
end | ||
|
||
container.spawn(name: "Jobs") do |instance| | ||
instance.exec("bundle", "exec", "jobs", ready: false) | ||
end | ||
end | ||
end | ||
|
||
controller = AppController.new | ||
|
||
controller.run |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/usr/bin/env ruby | ||
# frozen_string_literal: true | ||
|
||
require "console" | ||
require "async/container/notify" | ||
|
||
# Console.logger.debug! | ||
|
||
class Web | ||
def self.start = self.new.start | ||
|
||
def start | ||
Console.info(self, "Starting web...") | ||
|
||
if notify = Async::Container::Notify.open! | ||
Console.info(self, "Notifying container ready...") | ||
notify.ready! | ||
end | ||
|
||
loop do | ||
Console.info(self, "Web running...") | ||
|
||
sleep 10 | ||
end | ||
rescue Interrupt | ||
Console.info(self, "Exiting web...") | ||
end | ||
end | ||
|
||
Web.start |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters