pakyow-core 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b25fae34605893ca73a6ae5f244b0705eab56f924a5383982d204034e76bc4ff
4
- data.tar.gz: 9774485b7de8a3a2366ec51c5d6ff442a4f4c75d20707c3cccc2a07ded3d316e
3
+ metadata.gz: e4c1c5f27fb6ffae904ba62198bb53ce289f6c1f31336dd822fca00b126d95c8
4
+ data.tar.gz: de38ff2a793f66cebad1a1170c02e6b3978e07b38c8d973ac661efeb049e93ec
5
5
  SHA512:
6
- metadata.gz: 7322f92da626b39fab842d3003d0dee9efe58fae5c7d03771b369ca0d3750f5e55f5c6342ce225140fd29b0ac6e53fc44947f8de1b35337156246de9507ec38e
7
- data.tar.gz: b378d973b2a88d880aff0e6eb4538670e14cba02ab67b6b5f3a86212fc87dbd8668b66003e25dfcc19772aeddc8cc084663eb0e0d46c5340ac76c9a18dcbe177
6
+ metadata.gz: 6961b873b166f4d74ce23d7b9b86cd66f958e78b8371a3359c7044fdaa5b835a398356714663858ce897726cbd427104e6663bbf12a09b163dff815fc47316ef
7
+ data.tar.gz: 645210420f9bb6a5cc63ba794893d697642842f9de561fe5e00d9b93ee1831230bdcf860024630574e728992b40f40512ae2bc619648c9012480002f5a6d45f7
@@ -1,4 +1,31 @@
1
- # v1.0.2 (unreleased)
1
+ # v1.0.3 (unreleased)
2
+
3
+ * `fix` **Resolve several issues with respawns, restarts.**
4
+
5
+ *Related links:*
6
+ - [Pull Request #342][pr-342]
7
+
8
+ * `fix` **Ensure a logger and output is always available in the environment.**
9
+
10
+ *Related links:*
11
+ - [Pull Request #331][pr-331]
12
+
13
+ * `fix` **Start multiple processes when the process count specifies more than one.**
14
+
15
+ *Related links:*
16
+ - [Pull Request #329][pr-329]
17
+
18
+ * `fix` **Prevent failed processes from restarting indefinitely.**
19
+
20
+ *Related links:*
21
+ - [Pull Request #328][pr-328]
22
+
23
+ [pr-342]: https://github.com/pakyow/pakyow/pull/342
24
+ [pr-331]: https://github.com/pakyow/pakyow/pull/331
25
+ [pr-329]: https://github.com/pakyow/pakyow/pull/329
26
+ [pr-328]: https://github.com/pakyow/pakyow/pull/328
27
+
28
+ # v1.0.2
2
29
 
3
30
  * `fix` **Relocate `version.rb` from the meta gem into `pakyow/core`.**
4
31
  - Makes it possible to use `pakyow/core` and other gems without needing the meta gem.
@@ -44,6 +44,11 @@ module Pakyow
44
44
  end
45
45
  end
46
46
 
47
+ def touch_restart
48
+ FileUtils.mkdir_p(File.join(config.root, "tmp"))
49
+ FileUtils.touch(File.join(config.root, "tmp/restart.txt"))
50
+ end
51
+
47
52
  private
48
53
 
49
54
  def setup_for_restarting
@@ -53,15 +58,14 @@ module Pakyow
53
58
 
54
59
  # FIXME: this doesn't need to be hardcoded, but instead determined
55
60
  # from the source location when registered with the environment
56
- config.process.watched_paths << "./config/application.rb"
61
+ config.process.watched_paths << File.join(config.root, "config/application.rb")
57
62
 
58
63
  Thread.new do
59
64
  Filewatcher.new(
60
65
  config.process.watched_paths,
61
66
  exclude: config.process.excluded_paths
62
67
  ).watch do |_path, _event|
63
- FileUtils.mkdir_p "./tmp"
64
- FileUtils.touch "./tmp/restart.txt"
68
+ touch_restart
65
69
  end
66
70
  end
67
71
  end
@@ -13,13 +13,13 @@ module Pakyow
13
13
 
14
14
  # Other processes (e.g. apps) can touch this file to restart the server.
15
15
  #
16
- watch "./tmp/restart.txt" do
16
+ watch File.join(config.root, "tmp/restart.txt") do
17
17
  restart
18
18
  end
19
19
 
20
20
  # Automatically bundle.
21
21
  #
22
- watch "./Gemfile" do
22
+ watch File.join(config.root, "Gemfile") do
23
23
  Bundler.with_clean_env do
24
24
  Support::CLI::Runner.new(message: "Bundling").run("bundle install")
25
25
  end
@@ -27,7 +27,7 @@ module Pakyow
27
27
 
28
28
  # Respawn when the bundle changes.
29
29
  #
30
- watch "./Gemfile.lock" do
30
+ watch File.join(config.root, "Gemfile.lock") do
31
31
  respawn
32
32
  end
33
33
 
@@ -44,7 +44,9 @@ module Pakyow
44
44
  # Set the respawn flag and stop the process manager.
45
45
  # Pakyow will check the flag and respawn from the main thread.
46
46
  #
47
- @respawn = true; @process_manager.stop
47
+ @respawn = true
48
+ @bound_endpoint.close
49
+ @process_manager.stop
48
50
  end
49
51
  end
50
52
  end
@@ -16,7 +16,7 @@ module Pakyow
16
16
  extend Support::Extension
17
17
 
18
18
  apply_extension do
19
- unfreezable :process_manager
19
+ unfreezable :process_manager, :bound_endpoint
20
20
 
21
21
  class_state :processes, default: []
22
22
 
@@ -42,7 +42,7 @@ module Pakyow
42
42
  "http://#{config.server.host}:#{port}"
43
43
  )
44
44
 
45
- bound_endpoint = Async::Reactor.run {
45
+ @bound_endpoint = Async::Reactor.run {
46
46
  Async::IO::SharedEndpoint.bound(endpoint)
47
47
  }.wait
48
48
 
@@ -52,7 +52,7 @@ module Pakyow
52
52
  Processes::Server.new(
53
53
  protocol: endpoint.protocol,
54
54
  scheme: endpoint.scheme,
55
- endpoint: bound_endpoint
55
+ endpoint: @bound_endpoint
56
56
  ).run
57
57
  end
58
58
 
@@ -69,7 +69,7 @@ module Pakyow
69
69
  @processes << {
70
70
  name: name,
71
71
  block: block,
72
- count: count,
72
+ count: count.to_i,
73
73
  restartable: restartable
74
74
  }
75
75
  end
@@ -100,7 +100,7 @@ module Pakyow
100
100
  #
101
101
  exec "PW_RESPAWN=true #{$0} #{ARGV.join(" ")}"
102
102
  end
103
- rescue SignalException
103
+ rescue SignalException, Interrupt
104
104
  exit
105
105
  end
106
106
 
@@ -114,6 +114,7 @@ module Pakyow
114
114
  Pakyow.logger << "Goodbye"
115
115
 
116
116
  performing :shutdown do
117
+ @bound_endpoint.close
117
118
  @process_manager.stop
118
119
  end
119
120
  end
@@ -33,6 +33,7 @@ require "pakyow/actions/normalizer"
33
33
 
34
34
  require "pakyow/application"
35
35
 
36
+ require "pakyow/logger"
36
37
  require "pakyow/logger/destination"
37
38
  require "pakyow/logger/multiplexed"
38
39
  require "pakyow/logger/thread_local"
@@ -135,17 +136,32 @@ module Pakyow
135
136
  #
136
137
  attr_reader :env
137
138
 
138
- # Logger instance for the environment
139
+ # Any error encountered during the boot process
139
140
  #
140
- attr_reader :logger
141
+ attr_reader :error
141
142
 
142
- # Global logger instance
143
+ # Global log output.
144
+ #
145
+ # Builds and returns a default global output that's replaced in `setup`.
143
146
  #
144
- attr_reader :global_logger
147
+ def global_logger
148
+ unless defined?(@global_logger)
149
+ require "pakyow/logger/formatters/human"
150
+ @global_logger = Logger::Formatters::Human.new(
151
+ Logger::Destination.new(:stdout, $stdout)
152
+ )
153
+ end
145
154
 
146
- # Any error encountered during the boot process
155
+ @global_logger
156
+ end
157
+
158
+ # Logger instance for the environment.
147
159
  #
148
- attr_reader :error
160
+ # Builds and returns a default logger that's replaced in `setup`.
161
+ #
162
+ def logger
163
+ @logger ||= Logger.new("dflt", output: global_logger, level: :all)
164
+ end
149
165
 
150
166
  # Mounts an app at a path.
151
167
  #
@@ -200,20 +216,24 @@ module Pakyow
200
216
  end
201
217
 
202
218
  performing :setup do
203
- init_global_logger
219
+ destinations = Logger::Multiplexed.new(
220
+ *config.logger.destinations.map { |destination, io|
221
+ io.sync = config.logger.sync
222
+ Logger::Destination.new(destination, io)
223
+ }
224
+ )
225
+
226
+ @global_logger = config.logger.formatter.new(destinations)
227
+
228
+ @logger = Logger::ThreadLocal.new(
229
+ Logger.new("pkyw", output: @global_logger, level: config.logger.level)
230
+ )
231
+
232
+ Console.logger = Logger.new("asnc", output: @global_logger, level: :warn)
204
233
  end
205
234
 
206
235
  self
207
236
  rescue => error
208
- begin
209
- # Try again to initialize the logger, since we may have failed before that point.
210
- #
211
- unless Pakyow.logger
212
- init_global_logger
213
- end
214
- rescue
215
- end
216
-
217
237
  @setup_error = error; self
218
238
  end
219
239
 
@@ -344,23 +364,6 @@ module Pakyow
344
364
 
345
365
  private
346
366
 
347
- def init_global_logger
348
- destinations = Logger::Multiplexed.new(
349
- *config.logger.destinations.map { |destination, io|
350
- io.sync = config.logger.sync
351
- Logger::Destination.new(destination, io)
352
- }
353
- )
354
-
355
- @global_logger = config.logger.formatter.new(destinations)
356
-
357
- @logger = Logger::ThreadLocal.new(
358
- Logger.new("pkyw", output: @global_logger, level: config.logger.level)
359
- )
360
-
361
- Console.logger = Logger.new("asnc", output: @global_logger, level: :warn)
362
- end
363
-
364
367
  def ensure_setup_succeeded
365
368
  if @setup_error
366
369
  handle_boot_failure(@setup_error)
@@ -370,23 +373,11 @@ module Pakyow
370
373
  def handle_boot_failure(error)
371
374
  @error = error
372
375
 
373
- safe_logger do |logger|
374
- if logger.respond_to?(:houston)
375
- logger.houston(error)
376
- else
377
- logger.error(error)
378
- end
379
- end
376
+ logger.houston(error)
380
377
 
381
378
  if config.exit_on_boot_failure
382
379
  exit(false)
383
380
  end
384
381
  end
385
-
386
- require "logger"
387
-
388
- def safe_logger
389
- yield logger || ::Logger.new($stdout)
390
- end
391
382
  end
392
383
  end
@@ -36,18 +36,23 @@ module Pakyow
36
36
  private
37
37
 
38
38
  def run_process(process)
39
- Fiber.new {
40
- until @stopped
41
- status = @group.fork(process) {
42
- begin
43
- Async::Reactor.run(&process[:block])
39
+ process[:count].times do
40
+ Fiber.new {
41
+ until @stopped
42
+ status = @group.fork(process) do
43
+ Async do
44
+ process[:block].call
45
+ rescue => error
46
+ Pakyow.logger.houston(error)
47
+ exit 1
48
+ end
44
49
  rescue Interrupt
45
50
  end
46
- }
47
51
 
48
- break unless status.success?
49
- end
50
- }.resume
52
+ break unless status.success?
53
+ end
54
+ }.resume
55
+ end
51
56
  end
52
57
  end
53
58
  end
@@ -62,9 +62,9 @@ module Pakyow
62
62
  @validations.any?
63
63
  end
64
64
 
65
- def validate(validation_name = nil, **options)
65
+ def validate(validation_name = nil, **options, &block)
66
66
  validation_object = if block_given?
67
- Validations::Inline.new(validation_name, Proc.new)
67
+ Validations::Inline.new(validation_name, block)
68
68
  else
69
69
  self.class.validation_object_for(validation_name)
70
70
  end
@@ -3,5 +3,5 @@
3
3
  module Pakyow
4
4
  # Pakyow's current version.
5
5
  #
6
- VERSION = "1.0.2"
6
+ VERSION = "1.0.3"
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pakyow-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bryan Powell
8
8
  autorequire:
9
9
  bindir: commands
10
10
  cert_chain: []
11
- date: 2019-11-06 00:00:00.000000000 Z
11
+ date: 2019-12-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pakyow-support
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 1.0.2
19
+ version: 1.0.3
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 1.0.2
26
+ version: 1.0.3
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: async
29
29
  requirement: !ruby/object:Gem::Requirement