startback 0.13.0 → 0.14.0

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: 5b7ccc8dd2081ba0dffda6092a2dbb2a345b01e6b7231aee41aa506e85949a4a
4
- data.tar.gz: c53f396f235226bbbfd336c872a5e1334708e1dcc6ca62d456d7b969bf7baad2
3
+ metadata.gz: 3d5d880b8e9dfdeecdd68e78400468a2765dffbcf39866860daef9ac86a8096d
4
+ data.tar.gz: 6bf01ece248ca741ed4a590ab5458c8f94bda465c315951cfb0797fa49ae4fe9
5
5
  SHA512:
6
- metadata.gz: c5c4b8ecc4045efd18f206217ddc201c869929e1951e981bf07fae0a9ff710d60d00b444f871bac7096a8ee48f7b05f0d95498f58c3d737be5a5b08e3a626707
7
- data.tar.gz: d193c22d134a0f57403433a6e4f0279d74ca17aaf7d99278664a86c5a3d2118d7a926bc7a95957ad2e4bbe90a8fafb82f549a938e73d3996204aa98f0b19c4fc
6
+ metadata.gz: 7f21d629f5733aea63bdfd21199aae51208d16751e398a373cef0a72cf4fcbceb083046c7f1ec61f9ed4791c2e4621a787229f438622a35a28a9ca2591ec5f90
7
+ data.tar.gz: c77c9f93fc437a8c803782d226bd6f9c30497f1eb238a6244526262fd5c24e148b322d01d46ed8bd81d907b9851a9789e1774abaec5dccd63fefc8a0da50eeb1
@@ -1,18 +1,14 @@
1
1
  require 'rack'
2
- require 'webrick'
3
2
  require 'startback'
4
3
  module Startback
5
4
  class Event
6
5
  #
7
6
  # This class is the starting point of event handling in
8
7
  # Startback. It holds a Bus instance to which emitters
9
- # and listeners can connect, and the possibility for the
10
- # the listening part to start an infinite loop (ServerEngine).
8
+ # and listeners can connect.
11
9
  #
12
- # The Engine automatically runs a Webrick small webapp
13
- # with a /healthcheck webservice. The class can be extended
14
- # and method `on_health_check` overriden to run specific
15
- # checks.
10
+ # The Engine exposes a rack app (.rack_app) with a /healthcheck webservice.
11
+ # It is supposed to be mounted to a webserver such as puma.
16
12
  #
17
13
  # This class goes hand in hand with the `startback:engine`
18
14
  # docker image. It can be extended by subclasses to override
@@ -22,15 +18,13 @@ module Startback
22
18
  # - on_health_check to check specific health conditions
23
19
  # - create_agents to instantiate all listening agents
24
20
  # (unless auto_create_agents is used)
21
+ # - rack_app if you want to customize the API running
25
22
  #
26
23
  class Engine
27
24
  include Support::Robustness
28
25
 
29
26
  DEFAULT_OPTIONS = {
30
27
 
31
- # To be passed to ServerEngine
32
- server_engine: {}
33
-
34
28
  }
35
29
 
36
30
  def initialize(options = {}, context = Context.new)
@@ -60,7 +54,7 @@ module Startback
60
54
  end
61
55
 
62
56
  def bus
63
- ::Startback::Event::Bus.new
57
+ @bus ||= ::Startback::Event::Bus.new
64
58
  end
65
59
 
66
60
  def connect
@@ -68,20 +62,12 @@ module Startback
68
62
  bus.connect
69
63
  end
70
64
 
71
- def run(options = {})
72
- connect
73
-
74
- log(:info, self, "Running agents and server engine!")
75
- create_agents
76
- Runner.new(self, options[:server_engine] || {}).run
77
- end
78
-
79
65
  def create_agents
80
66
  return unless parent = self.class.auto_create_agents
81
67
 
82
68
  ObjectSpace
83
69
  .each_object(Class)
84
- .select { |klass| klass < parent }
70
+ .select { |klass| klass <= parent }
85
71
  .each { |klass| klass.new(self) }
86
72
  end
87
73
 
@@ -89,88 +75,20 @@ module Startback
89
75
  Event.json(event_data, context)
90
76
  end
91
77
 
92
- class Runner
93
-
94
- DEFAULT_SERVER_ENGINE_OPTIONS = {
95
- daemonize: false,
96
- worker_type: 'process',
97
- workers: 1
98
- }
99
-
100
- def initialize(engine, options = {})
101
- raise ArgumentError if engine.nil?
102
-
103
- @engine = engine
104
- @options = DEFAULT_SERVER_ENGINE_OPTIONS.merge(options)
105
- require 'serverengine'
106
- end
107
- attr_reader :engine, :options
108
-
109
- def run(options = {})
110
- health = self.class.build_health_check(engine)
111
- worker = self.class.build_worker(engine, health)
112
- se = ServerEngine.create(nil, worker, options)
113
- se.run
114
- se
115
- end
116
-
117
- class << self
118
- def run(*args, &bl)
119
- new.run(*args, &bl)
120
- end
78
+ def rack_app
79
+ engine = self
80
+ Rack::Builder.new do
81
+ use Startback::Web::CatchAll
121
82
 
122
- def build_health_check(engine)
123
- Rack::Builder.new do
124
- map '/health-check' do
125
- health = Startback::Web::HealthCheck.new {
126
- engine.on_health_check
127
- }
128
- run(health)
129
- end
130
- end
83
+ map '/health-check' do
84
+ health = Startback::Web::HealthCheck.new {
85
+ engine.on_health_check
86
+ }
87
+ run(health)
131
88
  end
89
+ end
90
+ end
132
91
 
133
- def build_worker(engine, health)
134
- Module.new do
135
- include Support::Env
136
-
137
- def initialize
138
- @stop_flag = ServerEngine::BlockingFlag.new
139
- end
140
-
141
- define_method(:health) do
142
- health
143
- end
144
-
145
- define_method(:engine) do
146
- engine
147
- end
148
-
149
- def run
150
- ran = false
151
- until @stop_flag.set?
152
- if ran
153
- engine.send(:log, :warn, engine, "Restarting internal loop")
154
- else
155
- engine.send(:log, :info, engine, "Starting internal loop")
156
- end
157
- Rack::Handler::WEBrick.run(health, {
158
- :Port => env('STARTBACK_ENGINE_PORT', '3000').to_i,
159
- :Host => env('STARTBACK_ENGINE_LISTEN', '0.0.0.0')
160
- })
161
- ran = true
162
- end
163
- end
164
-
165
- def stop
166
- engine.send(:log, :info, engine, "Stopping internal loop")
167
- @stop_flag.set!
168
- Rack::Handler::WEBrick.shutdown
169
- end
170
- end
171
- end
172
- end # class << self
173
- end # class Runner
174
92
  end # class Engine
175
93
  end # class Event
176
94
  end # module Startback
@@ -1,7 +1,7 @@
1
1
  module Startback
2
2
  module Version
3
3
  MAJOR = 0
4
- MINOR = 13
4
+ MINOR = 14
5
5
  TINY = 0
6
6
  end
7
7
  VERSION = "#{Version::MAJOR}.#{Version::MINOR}.#{Version::TINY}"
data/tasks/test.rake CHANGED
@@ -9,29 +9,6 @@ namespace :test do
9
9
  t.rspec_opts = %{-Ilib -Ispec --color --backtrace --format progress --format RspecJunitFormatter --out spec/rspec-unit.xml}
10
10
  end
11
11
 
12
- desc "Run the tests in the examples folder"
13
- task :example do
14
- Bundler.with_original_env do
15
- system("cd example && bundle exec rake")
16
- abort("Example tests failed") unless $?.exitstatus == 0
17
- end
18
- end
19
-
20
- contribs = (Path.dir.parent/"contrib").glob("*").map do |sub|
21
- next unless sub.directory?
22
- name = sub.basename.to_sym
23
-
24
- desc "Run tests for #{sub}"
25
- task name do
26
- Bundler.with_original_env do
27
- system("cd #{sub} && bundle exec rake")
28
- abort("#{sub} tests failed") unless $?.exitstatus == 0
29
- end
30
- end
31
-
32
- name
33
- end
34
-
35
- task :all => [:unit, :example] + contribs
12
+ task :all => [:unit]
36
13
  end
37
14
  task :test => :'test:all'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: startback
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.0
4
+ version: 0.14.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bernard Lambeau
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-05-31 00:00:00.000000000 Z
11
+ date: 2022-06-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -470,7 +470,7 @@ files:
470
470
  - spec/unit/web/test_healthcheck.rb
471
471
  - spec/unit/web/test_magic_assets.rb
472
472
  - tasks/test.rake
473
- homepage: http://www.enspirit.be
473
+ homepage: https://www.enspirit.be
474
474
  licenses:
475
475
  - MIT
476
476
  metadata: {}
@@ -489,7 +489,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
489
489
  - !ruby/object:Gem::Version
490
490
  version: '0'
491
491
  requirements: []
492
- rubygems_version: 3.3.7
492
+ rubygems_version: 3.1.2
493
493
  signing_key:
494
494
  specification_version: 4
495
495
  summary: Got Your Ruby Back