anway 0.1.1 → 0.2.0

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.
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'puma/plugin'
4
+ require 'anway'
5
+ require 'anway/puma/plugin'
6
+
7
+ # `plugin :anway` in config/puma.rb runs bin/anway next to Puma, as
8
+ # config/anway.yml says: the embedded server and the workers, or only the
9
+ # workers. ANWAY_IN_PUMA turns it on or off. Without it, it runs only in
10
+ # development. When anway stops by itself, Puma stops too, so a broken worker
11
+ # is not hidden.
12
+ Puma::Plugin.create do
13
+ def start(launcher)
14
+ @launcher = launcher
15
+
16
+ return unless Anway::Puma::Plugin.enabled?
17
+
18
+ events = launcher.events
19
+
20
+ if events.respond_to?(:after_booted)
21
+ events.after_booted { start_anway }
22
+ events.after_stopped { stop_anway }
23
+ events.before_restart { stop_anway }
24
+ else
25
+ events.on_booted { start_anway }
26
+ events.on_stopped { stop_anway }
27
+ events.on_restart { stop_anway }
28
+ end
29
+ end
30
+
31
+ private
32
+
33
+ def start_anway
34
+ @stopping = false
35
+ @pid = Process.spawn(*Anway::Puma::Plugin.command)
36
+
37
+ @monitor = Thread.new(@pid) do |pid|
38
+ _, status = Process.wait2(pid)
39
+
40
+ unless @stopping
41
+ log("anway stopped with #{status}, so Puma stops")
42
+ @launcher.stop
43
+ end
44
+ end
45
+
46
+ log("anway started with pid #{@pid}")
47
+ end
48
+
49
+ def stop_anway
50
+ return unless @pid
51
+
52
+ @stopping = true
53
+
54
+ Process.kill('TERM', @pid)
55
+
56
+ Process.kill('KILL', @pid) unless @monitor.join(Anway::Server::STOP_TIMEOUT + 5)
57
+ @monitor.join(5)
58
+ rescue Errno::ESRCH
59
+ nil
60
+ ensure
61
+ @pid = nil
62
+ end
63
+
64
+ def log(message)
65
+ writer = @launcher.respond_to?(:log_writer) ? @launcher.log_writer : @launcher.events
66
+
67
+ writer.log("* #{message}")
68
+ end
69
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: anway
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thadeu
@@ -37,16 +37,26 @@ files:
37
37
  - lib/anway/client.rb
38
38
  - lib/anway/configuration.rb
39
39
  - lib/anway/connection.rb
40
+ - lib/anway/console.rb
41
+ - lib/anway/daemon.rb
40
42
  - lib/anway/errors.rb
41
43
  - lib/anway/executor.rb
42
44
  - lib/anway/job.rb
43
45
  - lib/anway/pool.rb
46
+ - lib/anway/puma/plugin.rb
44
47
  - lib/anway/queues.rb
45
48
  - lib/anway/railtie.rb
46
49
  - lib/anway/runner.rb
50
+ - lib/anway/server.rb
51
+ - lib/anway/settings.rb
47
52
  - lib/anway/testing.rb
48
53
  - lib/anway/version.rb
54
+ - lib/anway/web.rb
49
55
  - lib/anway/worker.rb
56
+ - lib/generators/anway/install/install_generator.rb
57
+ - lib/generators/anway/install/templates/anway
58
+ - lib/generators/anway/install/templates/anway.yml
59
+ - lib/puma/plugin/anway.rb
50
60
  homepage: https://github.com/thadeu/anway-ruby
51
61
  licenses:
52
62
  - MIT