async-container 0.17.1 → 0.18.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/async/container/controller.rb +20 -11
- data/lib/async/container/group.rb +5 -0
- data/lib/async/container/notify/console.rb +2 -2
- data/lib/async/container/version.rb +1 -1
- data.tar.gz.sig +0 -0
- metadata +10 -22
- metadata.gz.sig +0 -0
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 7578abcb2db0aaab09b3e61f905b0a39f433521630fbc496b12e9042c25b54e7
         | 
| 4 | 
            +
              data.tar.gz: ac19ef8379687387ea79a17426b3197a713c6b4b0eb5d9e86f620d931e3fe3f0
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 5f335d1a6f5b7100660b458daf3014e62b52fed0f1ab0e67fcd8b914a0a87111027241348812f236af6c35c78e20461c7592270677dc577bc3f45b06c7142fb5
         | 
| 7 | 
            +
              data.tar.gz: 2309e4cec26af24d6f7af3a067858bade3db001f9ab3d0c300ff151f0489625b736e6388fa4a4c3b9c98b53d7e71d54a2e6a69ff8e9883a17d16ca1021968953
         | 
    
        checksums.yaml.gz.sig
    CHANGED
    
    | Binary file | 
| @@ -22,7 +22,7 @@ module Async | |
| 22 22 |  | 
| 23 23 | 
             
            			# Initialize the controller.
         | 
| 24 24 | 
             
            			# @parameter notify [Notify::Client] A client used for process readiness notifications.
         | 
| 25 | 
            -
            			def initialize(notify: Notify.open!, container_class: Container)
         | 
| 25 | 
            +
            			def initialize(notify: Notify.open!, container_class: Container, graceful_stop: true)
         | 
| 26 26 | 
             
            				@container = nil
         | 
| 27 27 | 
             
            				@container_class = container_class
         | 
| 28 28 |  | 
| @@ -35,6 +35,8 @@ module Async | |
| 35 35 | 
             
            				trap(SIGHUP) do
         | 
| 36 36 | 
             
            					self.restart
         | 
| 37 37 | 
             
            				end
         | 
| 38 | 
            +
            				
         | 
| 39 | 
            +
            				@graceful_stop = graceful_stop
         | 
| 38 40 | 
             
            			end
         | 
| 39 41 |  | 
| 40 42 | 
             
            			# The state of the controller.
         | 
| @@ -96,7 +98,7 @@ module Async | |
| 96 98 |  | 
| 97 99 | 
             
            			# Stop the container if it's running.
         | 
| 98 100 | 
             
            			# @parameter graceful [Boolean] Whether to give the children instances time to shut down or to kill them immediately.
         | 
| 99 | 
            -
            			def stop(graceful =  | 
| 101 | 
            +
            			def stop(graceful = @graceful_stop)
         | 
| 100 102 | 
             
            				@container&.stop(graceful)
         | 
| 101 103 | 
             
            				@container = nil
         | 
| 102 104 | 
             
            			end
         | 
| @@ -130,23 +132,25 @@ module Async | |
| 130 132 | 
             
            				if container.failed?
         | 
| 131 133 | 
             
            					@notify&.error!("Container failed to start!")
         | 
| 132 134 |  | 
| 133 | 
            -
            					container.stop
         | 
| 135 | 
            +
            					container.stop(false)
         | 
| 134 136 |  | 
| 135 137 | 
             
            					raise SetupError, container
         | 
| 136 138 | 
             
            				end
         | 
| 137 139 |  | 
| 138 | 
            -
            				#  | 
| 140 | 
            +
            				# The following swap should be atomic:
         | 
| 139 141 | 
             
            				old_container = @container
         | 
| 140 142 | 
             
            				@container = container
         | 
| 143 | 
            +
            				container = nil
         | 
| 144 | 
            +
            				
         | 
| 145 | 
            +
            				if old_container
         | 
| 146 | 
            +
            					Console.logger.debug(self, "Stopping old container...")
         | 
| 147 | 
            +
            					old_container&.stop(@graceful_stop)
         | 
| 148 | 
            +
            				end
         | 
| 141 149 |  | 
| 142 | 
            -
            				Console.logger.debug(self, "Stopping old container...")
         | 
| 143 | 
            -
            				old_container&.stop
         | 
| 144 150 | 
             
            				@notify&.ready!
         | 
| 145 | 
            -
            			 | 
| 151 | 
            +
            			ensure
         | 
| 146 152 | 
             
            				# If we are leaving this function with an exception, try to kill the container:
         | 
| 147 153 | 
             
            				container&.stop(false)
         | 
| 148 | 
            -
            				
         | 
| 149 | 
            -
            				raise
         | 
| 150 154 | 
             
            			end
         | 
| 151 155 |  | 
| 152 156 | 
             
            			# Reload the existing container. Children instances will be reloaded using `SIGHUP`.
         | 
| @@ -163,7 +167,9 @@ module Async | |
| 163 167 |  | 
| 164 168 | 
             
            				# Wait for all child processes to enter the ready state.
         | 
| 165 169 | 
             
            				Console.logger.debug(self, "Waiting for startup...")
         | 
| 170 | 
            +
            				
         | 
| 166 171 | 
             
            				@container.wait_until_ready
         | 
| 172 | 
            +
            				
         | 
| 167 173 | 
             
            				Console.logger.debug(self, "Finished startup.")
         | 
| 168 174 |  | 
| 169 175 | 
             
            				if @container.failed?
         | 
| @@ -180,14 +186,17 @@ module Async | |
| 180 186 | 
             
            				# I thought this was the default... but it doesn't always raise an exception unless you do this explicitly.
         | 
| 181 187 | 
             
            				# We use `Thread.current.raise(...)` so that exceptions are filtered through `Thread.handle_interrupt` correctly.
         | 
| 182 188 | 
             
            				interrupt_action = Signal.trap(:INT) do
         | 
| 189 | 
            +
            					# $stderr.puts "Received INT signal, terminating...", caller
         | 
| 183 190 | 
             
            					::Thread.current.raise(Interrupt)
         | 
| 184 191 | 
             
            				end
         | 
| 185 192 |  | 
| 186 193 | 
             
            				terminate_action = Signal.trap(:TERM) do
         | 
| 194 | 
            +
            					# $stderr.puts "Received TERM signal, terminating...", caller
         | 
| 187 195 | 
             
            					::Thread.current.raise(Terminate)
         | 
| 188 196 | 
             
            				end
         | 
| 189 197 |  | 
| 190 198 | 
             
            				hangup_action = Signal.trap(:HUP) do
         | 
| 199 | 
            +
            					# $stderr.puts "Received HUP signal, restarting...", caller
         | 
| 191 200 | 
             
            					::Thread.current.raise(Hangup)
         | 
| 192 201 | 
             
            				end
         | 
| 193 202 |  | 
| @@ -209,11 +218,11 @@ module Async | |
| 209 218 | 
             
            					end
         | 
| 210 219 | 
             
            				end
         | 
| 211 220 | 
             
            			rescue Interrupt
         | 
| 212 | 
            -
            				self.stop | 
| 221 | 
            +
            				self.stop
         | 
| 213 222 | 
             
            			rescue Terminate
         | 
| 214 223 | 
             
            				self.stop(false)
         | 
| 215 224 | 
             
            			ensure
         | 
| 216 | 
            -
            				self.stop( | 
| 225 | 
            +
            				self.stop(false)
         | 
| 217 226 |  | 
| 218 227 | 
             
            				# Restore the interrupt handler:
         | 
| 219 228 | 
             
            				Signal.trap(:INT, interrupt_action)
         | 
| @@ -20,6 +20,10 @@ module Async | |
| 20 20 | 
             
            				@queue = nil
         | 
| 21 21 | 
             
            			end
         | 
| 22 22 |  | 
| 23 | 
            +
            			def inspect
         | 
| 24 | 
            +
            				"#<#{self.class} running=#{@running.size}>"
         | 
| 25 | 
            +
            			end
         | 
| 26 | 
            +
            			
         | 
| 23 27 | 
             
            			# @attribute [Hash(IO, Fiber)] the running tasks, indexed by IO.
         | 
| 24 28 | 
             
            			attr :running
         | 
| 25 29 |  | 
| @@ -133,6 +137,7 @@ module Async | |
| 133 137 | 
             
            			protected
         | 
| 134 138 |  | 
| 135 139 | 
             
            			def wait_for_children(duration = nil)
         | 
| 140 | 
            +
            				Console.debug(self, "Waiting for children...", duration: duration)
         | 
| 136 141 | 
             
            				if !@running.empty?
         | 
| 137 142 | 
             
            					# Maybe consider using a proper event loop here:
         | 
| 138 143 | 
             
            					readable, _, _ = ::IO.select(@running.keys, nil, nil, duration)
         | 
| @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            # frozen_string_literal: true
         | 
| 2 2 |  | 
| 3 3 | 
             
            # Released under the MIT License.
         | 
| 4 | 
            -
            # Copyright, 2020- | 
| 4 | 
            +
            # Copyright, 2020-2024, by Samuel Williams.
         | 
| 5 5 |  | 
| 6 6 | 
             
            require_relative 'client'
         | 
| 7 7 |  | 
| @@ -13,7 +13,7 @@ module Async | |
| 13 13 | 
             
            			# Implements a general process readiness protocol with output to the local console.
         | 
| 14 14 | 
             
            			class Console < Client
         | 
| 15 15 | 
             
            				# Open a notification client attached to the current console.
         | 
| 16 | 
            -
            				def self.open!(logger = ::Console | 
| 16 | 
            +
            				def self.open!(logger = ::Console)
         | 
| 17 17 | 
             
            					self.new(logger)
         | 
| 18 18 | 
             
            				end
         | 
| 19 19 |  | 
    
        data.tar.gz.sig
    CHANGED
    
    | Binary file | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: async-container
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0. | 
| 4 | 
            +
              version: 0.18.1
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Samuel Williams
         | 
| @@ -41,36 +41,22 @@ cert_chain: | |
| 41 41 | 
             
              Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
         | 
| 42 42 | 
             
              voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
         | 
| 43 43 | 
             
              -----END CERTIFICATE-----
         | 
| 44 | 
            -
            date: 2024- | 
| 44 | 
            +
            date: 2024-04-24 00:00:00.000000000 Z
         | 
| 45 45 | 
             
            dependencies:
         | 
| 46 46 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 47 47 | 
             
              name: async
         | 
| 48 48 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 49 49 | 
             
                requirements:
         | 
| 50 | 
            -
                - - " | 
| 50 | 
            +
                - - "~>"
         | 
| 51 51 | 
             
                  - !ruby/object:Gem::Version
         | 
| 52 | 
            -
                    version: ' | 
| 52 | 
            +
                    version: '2.10'
         | 
| 53 53 | 
             
              type: :runtime
         | 
| 54 54 | 
             
              prerelease: false
         | 
| 55 55 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 56 56 | 
             
                requirements:
         | 
| 57 | 
            -
                - - " | 
| 57 | 
            +
                - - "~>"
         | 
| 58 58 | 
             
                  - !ruby/object:Gem::Version
         | 
| 59 | 
            -
                    version: ' | 
| 60 | 
            -
            - !ruby/object:Gem::Dependency
         | 
| 61 | 
            -
              name: async-io
         | 
| 62 | 
            -
              requirement: !ruby/object:Gem::Requirement
         | 
| 63 | 
            -
                requirements:
         | 
| 64 | 
            -
                - - ">="
         | 
| 65 | 
            -
                  - !ruby/object:Gem::Version
         | 
| 66 | 
            -
                    version: '0'
         | 
| 67 | 
            -
              type: :runtime
         | 
| 68 | 
            -
              prerelease: false
         | 
| 69 | 
            -
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 70 | 
            -
                requirements:
         | 
| 71 | 
            -
                - - ">="
         | 
| 72 | 
            -
                  - !ruby/object:Gem::Version
         | 
| 73 | 
            -
                    version: '0'
         | 
| 59 | 
            +
                    version: '2.10'
         | 
| 74 60 | 
             
            description:
         | 
| 75 61 | 
             
            email:
         | 
| 76 62 | 
             
            executables: []
         | 
| @@ -103,7 +89,9 @@ files: | |
| 103 89 | 
             
            homepage: https://github.com/socketry/async-container
         | 
| 104 90 | 
             
            licenses:
         | 
| 105 91 | 
             
            - MIT
         | 
| 106 | 
            -
            metadata: | 
| 92 | 
            +
            metadata:
         | 
| 93 | 
            +
              documentation_uri: https://socketry.github.io/async-container/
         | 
| 94 | 
            +
              source_code_uri: https://github.com/socketry/async-container.git
         | 
| 107 95 | 
             
            post_install_message:
         | 
| 108 96 | 
             
            rdoc_options: []
         | 
| 109 97 | 
             
            require_paths:
         | 
| @@ -112,7 +100,7 @@ required_ruby_version: !ruby/object:Gem::Requirement | |
| 112 100 | 
             
              requirements:
         | 
| 113 101 | 
             
              - - ">="
         | 
| 114 102 | 
             
                - !ruby/object:Gem::Version
         | 
| 115 | 
            -
                  version: '3. | 
| 103 | 
            +
                  version: '3.1'
         | 
| 116 104 | 
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 117 105 | 
             
              requirements:
         | 
| 118 106 | 
             
              - - ">="
         | 
    
        metadata.gz.sig
    CHANGED
    
    | Binary file |