startback 0.13.0 → 0.14.2

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: b170ad4acdf67e94658b9f22c96e22d9117ee35864992bfe0f69e831e4273688
4
+ data.tar.gz: 1e3de02cb0635e50ab5435176619c580f9429d89af766737c7419da3aaca9a1e
5
5
  SHA512:
6
- metadata.gz: c5c4b8ecc4045efd18f206217ddc201c869929e1951e981bf07fae0a9ff710d60d00b444f871bac7096a8ee48f7b05f0d95498f58c3d737be5a5b08e3a626707
7
- data.tar.gz: d193c22d134a0f57403433a6e4f0279d74ca17aaf7d99278664a86c5a3d2118d7a926bc7a95957ad2e4bbe90a8fafb82f549a938e73d3996204aa98f0b19c4fc
6
+ metadata.gz: 9a9a4dbeb2cbe2d833dc2f1892476ee3181ceec68c0b52c14b3e2cdec0521cbe7b857ed4ef5a3e2b8ba3e682130d021265becc13c662cdd2a1f164b0f76c14ab
7
+ data.tar.gz: 6cb1f10d1a0c78f55c132b44a6f37ba1dea98a1a673b79e6ce7efe392567e43272ea7d3b584584deb4fc18c1013f88003a6233844e5137a19ce5cefcf840b135
@@ -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,8 +1,8 @@
1
1
  module Startback
2
2
  module Version
3
3
  MAJOR = 0
4
- MINOR = 13
5
- TINY = 0
4
+ MINOR = 14
5
+ TINY = 2
6
6
  end
7
7
  VERSION = "#{Version::MAJOR}.#{Version::MINOR}.#{Version::TINY}"
8
8
  end
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.2
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-08 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