Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Container example doesn't actually initialize anything #15

Open
tadman opened this issue Apr 30, 2020 · 3 comments
Open

Container example doesn't actually initialize anything #15

tadman opened this issue Apr 30, 2020 · 3 comments

Comments

@tadman
Copy link

tadman commented Apr 30, 2020

The container example runs without doing anything:

controller = Async::Container::Controller.new do |container|
	Async.logger.debug(self, "Setting up container...")
	
	container.run(count: 1, restart: true) do
		Async.logger.debug(self, "Child process started.")
		
		while true
			sleep 1
			
			if rand < 0.1
				exit(1)
			end
		end
	ensure
		Async.logger.debug(self, "Child process exiting:", $!)
	end
end

begin
	controller.run
ensure
	Async.logger.debug(controller, "Parent process exiting:", $!)
end

Where the output is:

0.11s: Object
      | Starting up...
 0.11s: Async::Container::Notify::Console
      | {:status=>"Initializing..."}
 0.11s: Async::Container::Controller
      | Starting container...
 0.11s: Async::Container::Controller
      | Waiting for startup...
 0.11s: Async::Container::Forked
      | Waiting for ready:
 0.11s: Async::Container::Controller
      | Finished startup.
 0.11s: Async::Container::Notify::Console
      | {:ready=>true}
 0.11s: Async::Container::Controller
      | Parent process exiting:

There's no mention of a "Child process" in there because the block is ignored.

@tadman
Copy link
Author

tadman commented Apr 30, 2020

A reworked example that seems to function:

class ExampleController < Async::Container::Controller
  def setup(container)
    Async.logger.debug(self, "Container established.")
    
    container.run(count: 1, restart: true) do |instance|
      Async.logger.debug(self, "Child process started.")
      
      Async do |task|
        loop do
          task.sleep(1)
        end
      end

      instance.ready!

    ensure
      Async.logger.debug(self, "Child process exiting:", $!)
    end
  end
end

begin
  controller = ExampleController.new

  controller.run
  
ensure
  Async.logger.debug(controller, "Parent process exiting:", $!)
end

Where the setup method needs to be customized. Presumably new could capture that block and use it within setup?

@ioquatix
Copy link
Member

ioquatix commented May 1, 2020

I had it that way before but decided against it as a general pattern it's too magical and literally doesn't even really save more than a few lines of code.

@ioquatix
Copy link
Member

Sorry, I don't understand my reply at all haha. I'm going to review this again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants