type_fusion 0.0.4 → 0.0.6

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: 7eaa132f18093b5b57b9db4e49130adb2f9ff41ae03559848e1334ee4f863bfe
4
- data.tar.gz: 4bc9dcc31808f3f39707516436f28a3e73de19054f80c2d143da66dc365ae106
3
+ metadata.gz: b9c5749c381eccd5f84c5d824fce4d634cde7bda503638dfef9c9737b61c7cb0
4
+ data.tar.gz: 6fc4cb00bf6ddb01f0832962df93add41020668d2de5ca3933c3619039bbda96
5
5
  SHA512:
6
- metadata.gz: '086356eb24932d3fbce347967869de8ba31672ebde52eaed096a640713ca8cb69e151ebe2a6dd71ebdb596a07cd6ea971bcf7f0147887059a344901d08e2be90'
7
- data.tar.gz: 35dbb641e2ffc414aa0c42af6f2a61538f3a24f37e5bd35daf623bc7824b853fe8963711c10fd741e2e6155be6b73cf26fd7718f530b36e238c912f2ce372f7b
6
+ metadata.gz: 1b1c116b16c6f56234a1718af703c0c8e64527230e9cb74f4efae26727a467e30ac63b233f0f075f8494b1fc40096d3bf113b03bd0ab409f3088e7332c09a04f
7
+ data.tar.gz: a687bce21925739f806d3cb458a08e301723db19d755dcc04f3de47098fbe4236ccb30a84fa6e2845be6553cad92f1a1145464fe16483a0416ed0650cf8a969a
data/CHANGELOG.md CHANGED
@@ -1,4 +1,18 @@
1
- ## [Unreleased]
1
+ ## [0.0.6] - 2023-08-25
2
+
3
+ - Add support for running TypeFusion in the test environment with RSpec
4
+ - Update Struct syntax for Ruby 3.2/3.1 compatibility
5
+ - Show how many threads are processing samples
6
+ - Rename `TypeFusion::Processor#enqueued_samples` to `#enqueued_jobs`
7
+ - Move `TypeFusion::Processor` signal trap to `#process!` so it doesn't interfere with the Rails server
8
+ - Keep track of started state of `TypeFusion::Processor` so we only need to start the processing once
9
+
10
+ ## [0.0.5] - 2023-08-25
11
+
12
+ - Introduce `TypeFusion::Processor` for processing samples
13
+ - Add support for running TypeFusion in the test environment with Minitest
14
+ - Rescue and log when job failed to enqueue
15
+ - Add Rake task for manually processing enqueued jobs
2
16
 
3
17
  ## [0.0.4] - 2023-08-16
4
18
 
data/Gemfile.lock CHANGED
@@ -1,14 +1,14 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- type_fusion (0.0.4)
4
+ type_fusion (0.0.6)
5
5
  lhc (~> 15.2)
6
6
  litejob (~> 0.2.3)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- activesupport (7.0.7)
11
+ activesupport (7.0.7.2)
12
12
  concurrent-ruby (~> 1.0, >= 1.0.2)
13
13
  i18n (>= 1.6, < 2)
14
14
  minitest (>= 5.1)
@@ -54,7 +54,7 @@ GEM
54
54
  rake (13.0.6)
55
55
  regexp_parser (2.8.1)
56
56
  rexml (3.2.6)
57
- rubocop (1.56.0)
57
+ rubocop (1.56.1)
58
58
  base64 (~> 0.1.1)
59
59
  json (~> 2.3)
60
60
  language_server-protocol (>= 3.17.0)
data/README.md CHANGED
@@ -14,6 +14,44 @@ If bundler is not being used to manage dependencies, install the gem by executin
14
14
  gem install type_fusion
15
15
  ```
16
16
 
17
+ ### Running TypeFusion in the `test` environment
18
+
19
+ Setup TypeFusion if you only want to run TypeFusion as part of your test suite.
20
+
21
+ #### Minitest
22
+
23
+ You can require `type_fusion/minitest` in your `test_helper.rb`:
24
+
25
+ ```diff
26
+ # test/test_helper.rb
27
+
28
+ ENV["RAILS_ENV"] ||= "test"
29
+ require_relative "../config/environment"
30
+ require "rails/test_help"
31
+
32
+ +require "type_fusion/minitest"
33
+
34
+ class ActiveSupport::TestCase
35
+ # ...
36
+ end
37
+ ```
38
+
39
+ #### RSpec
40
+
41
+ You can require `type_fusion/rspec` in your `spec_helper.rb`:
42
+
43
+ ```diff
44
+ # spec/spec_helper.rb
45
+
46
+ +require "type_fusion/rspec"
47
+
48
+ RSpec.configure do |config|
49
+ # ...
50
+ end
51
+ ```
52
+
53
+ ### Running TypeFusion in `development` or `production`
54
+
17
55
  #### Rack
18
56
 
19
57
  ```ruby
@@ -27,6 +65,7 @@ use TypeFusion::Middleware
27
65
  Adding the gem to your applications Gemfile will automatically setup `type_fusion`.
28
66
 
29
67
 
68
+
30
69
  ## Configuration
31
70
 
32
71
  Setup `TypeFusion` in an initializer
@@ -134,19 +173,20 @@ TypeFusion::Sampler.instance.samples
134
173
  TypeFusion::Sampler.instance.samples.first
135
174
 
136
175
  # => #<struct TypeFusion::SampleCall
137
- # gem_and_version="nokogiri-1.15.4-x86_64-darwin",
176
+ # gem_name="nokogiri"
177
+ # gem_version="1.15.4-x86_64-darwin",
138
178
  # receiver="Nokogiri",
139
179
  # method_name=:parse,
140
- # location=[
141
- # "/Users/marcoroth/.anyenv/envs/rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/nokogiri-1.15.4-x86_64-darwin/lib/nokogiri.rb",
142
- # 43
143
- # ],
180
+ # application_name="TypeFusion",
181
+ # location="/Users/marcoroth/.anyenv/envs/rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/nokogiri-1.15.4-x86_64-darwin/lib/nokogiri.rb:43",
182
+ # type_fusion_version="0.0.4",
144
183
  # parameters=[
145
184
  # [:string, :req, String],
146
185
  # [:url, :opt, NilClass],
147
186
  # [:encoding, :opt, NilClass],
148
187
  # [:options, :opt, NilClass]
149
- # ]
188
+ # ],
189
+ # return_value="Nokogiri::XML::Document"
150
190
  # >
151
191
  ```
152
192
 
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ namespace :type_fusion do
4
+ desc "Process enqueued type samples"
5
+ task :process do
6
+ TypeFusion.processor.process!
7
+ end
8
+ end
@@ -23,7 +23,7 @@ module TypeFusion
23
23
  @type_sample_call_rate = 0.001
24
24
  @type_sample_request = ->(_env) { [true, false, false, false].sample }
25
25
  @type_sample_tracepoint_path = ->(_tracepoint_path) { true }
26
- @endpoint = "http://localhost:3000/api/v1/types/samples"
26
+ @endpoint = "https://gem.sh/api/v1/types/samples"
27
27
  @application_name = "TypeFusion"
28
28
  end
29
29
 
@@ -5,3 +5,10 @@ require "litejob"
5
5
  # Litequeue.configure do |config|
6
6
  # config.path = "db/type_fusion/queue.sqlite3"
7
7
  # end
8
+
9
+ Litejob.configure do |config|
10
+ config.logger = Class.new do
11
+ def self.info(*args)
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../type_fusion"
4
+
5
+ TypeFusion.start
6
+
7
+ Minitest.after_run do
8
+ TypeFusion.stop
9
+ TypeFusion.processor.process!
10
+ end
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TypeFusion
4
+ class Processor
5
+ def initialize(amount = 4)
6
+ @amount = amount
7
+ @servers = []
8
+ @started = false
9
+ end
10
+
11
+ def should_run?
12
+ enqueued_jobs.positive?
13
+ end
14
+
15
+ def started?
16
+ @started
17
+ end
18
+
19
+ def enqueued_jobs
20
+ Litequeue.instance.count
21
+ end
22
+
23
+ def stop!
24
+ @servers.each do |server|
25
+ server.instance_variable_get(:@scheduler).context.kill
26
+ end
27
+ @servers = []
28
+ @started = false
29
+ end
30
+
31
+ def start!
32
+ @amount.times do
33
+ @servers << Litejob::Server.new
34
+ end
35
+ @started = true
36
+ end
37
+
38
+ def process!
39
+ puts "[TypeFusion] Start processing of #{enqueued_jobs} samples using #{@amount} threads..."
40
+
41
+ Signal.trap("INT") do
42
+ puts "\n[TypeFusion] Stop processing of TypeFusion samples..."
43
+ stop!
44
+ end
45
+
46
+ start!
47
+
48
+ while should_run?
49
+ puts "[TypeFusion] Remaining samples: #{Litequeue.instance.count}"
50
+ sleep 1
51
+ end
52
+
53
+ puts "[TypeFusion] Finished!"
54
+
55
+ puts "[TypeFusion] Congratulations! You just contributed samples to the following gems and helped making the Ruby ecosystem better for the whole community! Thank you!\n"
56
+ puts "- #{gems.join("\n- ")}"
57
+
58
+ stop!
59
+ end
60
+
61
+ private
62
+
63
+ def gems
64
+ TypeFusion::Sampler.instance.samples.map(&:gem_name).uniq.sort
65
+ end
66
+ end
67
+ end
@@ -16,6 +16,8 @@ module TypeFusion
16
16
 
17
17
  @app.call(env)
18
18
  ensure
19
+ TypeFusion.start_processing unless TypeFusion.processor.started?
20
+
19
21
  TypeFusion.stop
20
22
  end
21
23
  end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../type_fusion"
4
+
5
+ TypeFusion.start
6
+
7
+ RSpec.configure do |config|
8
+ config.after(:suite) do
9
+ TypeFusion.stop
10
+ TypeFusion.processor.process!
11
+ end
12
+ end
@@ -10,7 +10,6 @@ module TypeFusion
10
10
 
11
11
  def initialize
12
12
  @samples = []
13
- @litejob_server ||= Litejob::Server.new([["default", 1]])
14
13
  end
15
14
 
16
15
  def with_sampling
@@ -38,20 +37,27 @@ module TypeFusion
38
37
  parameters = extract_parameters(args, tracepoint.binding)
39
38
  return_value = type_for_object(tracepoint.return_value)
40
39
 
41
- sample = SampleCall.new(
40
+ sample_values = {
42
41
  gem_name: gem,
43
42
  gem_version: version,
44
43
  receiver: receiver,
45
44
  method_name: method_name,
45
+ application_name: TypeFusion.config.application_name,
46
46
  location: location,
47
47
  type_fusion_version: VERSION,
48
48
  parameters: parameters,
49
- application_name: TypeFusion.config.application_name,
50
49
  return_value: return_value,
51
- )
50
+ }
51
+
52
+ sample = SampleCall.new(*sample_values.values)
52
53
 
53
54
  samples << sample
54
- SampleJob.perform_async(sample)
55
+
56
+ begin
57
+ SampleJob.perform_async(sample)
58
+ rescue StandardError => e
59
+ puts "[TypeFusion] Couldn't enqueue sample: #{e.inspect}"
60
+ end
55
61
  end
56
62
  end.tap(&:disable)
57
63
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TypeFusion
4
- VERSION = "0.0.4"
4
+ VERSION = "0.0.6"
5
5
  end
data/lib/type_fusion.rb CHANGED
@@ -6,6 +6,7 @@ require_relative "type_fusion/litejob"
6
6
  require_relative "type_fusion/sample_call"
7
7
  require_relative "type_fusion/sample_job"
8
8
  require_relative "type_fusion/sampler"
9
+ require_relative "type_fusion/processor"
9
10
 
10
11
  module TypeFusion
11
12
  class << self
@@ -23,6 +24,16 @@ module TypeFusion
23
24
  Sampler.instance.trace.disable
24
25
  end
25
26
 
27
+ def start_processing
28
+ puts "[TypeFusion] Start processing..."
29
+ processor.start!
30
+ end
31
+
32
+ def stop_processing
33
+ puts "[TypeFusion] Stop processing..."
34
+ processor.stop!
35
+ end
36
+
26
37
  def with_sampling
27
38
  start
28
39
 
@@ -30,6 +41,10 @@ module TypeFusion
30
41
 
31
42
  stop
32
43
  end
44
+
45
+ def processor
46
+ @processor ||= TypeFusion::Processor.new(4)
47
+ end
33
48
  end
34
49
  end
35
50
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: type_fusion
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marco Roth
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-08-15 00:00:00.000000000 Z
11
+ date: 2023-08-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lhc
@@ -53,11 +53,15 @@ files:
53
53
  - Gemfile.lock
54
54
  - README.md
55
55
  - Rakefile
56
+ - lib/tasks/type_fusion.rake
56
57
  - lib/type_fusion.rb
57
58
  - lib/type_fusion/config.rb
58
59
  - lib/type_fusion/litejob.rb
60
+ - lib/type_fusion/minitest.rb
61
+ - lib/type_fusion/processor.rb
59
62
  - lib/type_fusion/rack/middleware.rb
60
63
  - lib/type_fusion/rails/railtie.rb
64
+ - lib/type_fusion/rspec.rb
61
65
  - lib/type_fusion/sample_call.rb
62
66
  - lib/type_fusion/sample_job.rb
63
67
  - lib/type_fusion/sampler.rb
@@ -86,7 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
86
90
  - !ruby/object:Gem::Version
87
91
  version: '0'
88
92
  requirements: []
89
- rubygems_version: 3.4.17
93
+ rubygems_version: 3.3.26
90
94
  signing_key:
91
95
  specification_version: 4
92
96
  summary: Community-contributed sample data for Ruby types