track_ballast 0.1.0 → 0.3.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6e862c2e25e1e2fcd384d009cefe352c350914732709276274e5013254e58296
4
- data.tar.gz: debd71ea18ded7b48e053473fe1cd516bbe82658dcf30407dcfb93437a021193
3
+ metadata.gz: 4595b4b0cb3973ed3cb28bcdf309fda53718f628b0f8042f319224acf7a30f76
4
+ data.tar.gz: b76c47871cb4974015cb7d580698296368f10325ad54c36a03736d1cb2f40e10
5
5
  SHA512:
6
- metadata.gz: '09f2866179582e548cba5e16a5a8afb06942abbe10b891626bb2f1dd1f1d87ba3cce5a1e1d596d8f95bd9b7b8494bad67d45c51d3f0151e30b5b782d6f899048'
7
- data.tar.gz: 210396ca3d3d363dc47529d7fe0c3c54f48995c6d21725a26116c741f0b4ded76c61f5e564443ec6a402144fcacb46cf08588d6f1d61e8ffa6c95aba47f2da81
6
+ metadata.gz: a4494a7b7941ae681e77a0d3c4a12dc31fc49c2a7a60bb5e7d02fafd793de57da2544cc8aca5fdd5982d3195f289e740622f638d91ed334d1e4ed9b948b386b7
7
+ data.tar.gz: 8e17fdf3a516d75234438f103273bc227e1e45f9b742d635807e4618c22053d6ea276563cfd30215555dbd7cc53ee1a4f98c117f3f6dc46947bac4cf544e31c3
data/.circleci/config.yml CHANGED
@@ -16,7 +16,11 @@ executors:
16
16
  default: 3.2.2
17
17
  resource_class: small
18
18
  docker:
19
- - image: cimg/ruby:<< parameters.ruby-version >>
19
+ - image: cimg/ruby:<< parameters.ruby-version >>
20
+ environment:
21
+ REDIS_URL: redis://localhost:6379
22
+ BUNDLE_VERSION: 2.5.5
23
+ - image: cimg/redis:6.2
20
24
 
21
25
  commands:
22
26
  bundle_install:
@@ -70,6 +74,12 @@ commands:
70
74
  read -r target_gemname target_version \<<< $( echo "<< parameters.gem-version >>" | sed 's/\(.*\)-\([0-9]\{1,3\}\(\.[0-9]\{1,3\}\)*\)/\1 \2/g')
71
75
  gem install $target_gemname -i /tmp/repo --no-document -v $target_version
72
76
 
77
+ # Install sqlite3 2.1.0 if we're using Rails 8
78
+ if [[ "$target_gemname" = "rails" && "$target_version" =~ ^8\. ]]; then
79
+ echo "Detected Rails 8.x, installing sqlite3 2.1.0"
80
+ gem install sqlite3 -i /tmp/repo --no-document -v 2.1.0
81
+ fi
82
+
73
83
  echo 'Delete any gems matching the newly installed ones from the existing cache'
74
84
  for line in $(ls /tmp/repo/cache | grep gem); do
75
85
  read -r gemname version \<<< $( echo $line | sed 's/\(.*\)-\([0-9]\{1,3\}\(\.[0-9]\{1,3\}\)*\)[^0-9\.]*.*.gem/\1 \2/g')
@@ -224,12 +234,10 @@ workflows:
224
234
  path: tmp/test-results
225
235
  matrix:
226
236
  parameters:
227
- ruby-version:
228
- - '3.0'
229
- - '3.1'
230
- - '3.2'
231
- - '3.3'
232
- gem-version:
233
- - rails-6.1.7
234
- - rails-7.0.8
235
- - rails-7.1.3
237
+ ruby-version: ['3.0', '3.1', '3.2', '3.3']
238
+ gem-version: ['rails-7.0.8', 'rails-7.1.3', 'rails-8.0.2']
239
+ exclude:
240
+ - ruby-version: '3.0'
241
+ gem-version: 'rails-8.0.2'
242
+ - ruby-version: '3.1'
243
+ gem-version: 'rails-8.0.2'
data/CHANGELOG.md CHANGED
@@ -1,6 +1,17 @@
1
1
  Changelog
2
2
  =========
3
3
 
4
+ ## 0.3.0
5
+
6
+ * Added support for Rails 8
7
+ * Updated ActiveRecord and ActiveSupport dependencies to support Rails 7.0 - 8.x
8
+
9
+ ## 0.2.0
10
+
11
+ * Added `redis` dependency
12
+ * Added `TrackBallast.redis`
13
+ * Added `StopSignal`
14
+
4
15
  ## 0.1.0
5
16
 
6
17
  * First external release
data/Gemfile.lock CHANGED
@@ -1,9 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- track_ballast (0.1.0)
5
- activerecord (>= 6.1, < 8.0)
6
- activesupport (>= 6.1, < 8.0)
4
+ track_ballast (0.3.0)
5
+ activerecord (>= 7.0, < 9.0)
6
+ activesupport (>= 7.0, < 9.0)
7
+ redis (>= 4.8, < 6.0)
7
8
 
8
9
  GEM
9
10
  remote: https://rubygems.org/
@@ -78,6 +79,10 @@ GEM
78
79
  rb-fsevent (0.11.2)
79
80
  rb-inotify (0.10.1)
80
81
  ffi (~> 1.0)
82
+ redis (5.0.8)
83
+ redis-client (>= 0.17.0)
84
+ redis-client (0.19.1)
85
+ connection_pool
81
86
  regexp_parser (2.9.0)
82
87
  rexml (3.2.6)
83
88
  rspec (3.12.0)
@@ -138,6 +143,7 @@ GEM
138
143
  PLATFORMS
139
144
  arm64-darwin-21
140
145
  arm64-darwin-22
146
+ arm64-darwin-24
141
147
  x86_64-linux
142
148
 
143
149
  DEPENDENCIES
data/README.md CHANGED
@@ -22,6 +22,16 @@ Or install it yourself as:
22
22
 
23
23
  $ gem install track_ballast
24
24
 
25
+ If you wish to use features that rely on Redis, you may set a Redis connection to `TrackBallast.redis`.
26
+
27
+ For Rails, you may wish to set up TrackBallast using an initializer, though **please note**, the default configuration may be appropriate. Please see the `TrackBallast.redis` documentation for details.
28
+
29
+ ```ruby
30
+ # config/initializers/track_ballast.rb
31
+
32
+ TrackBallast.redis = Redis.new(url: ENV["CUSTOM_REDIS_URL"])
33
+ ```
34
+
25
35
  ## Usage
26
36
 
27
37
  Please see [the code](https://github.com/doximity/track_ballast/tree/master/lib/track_ballast) and [documentation](https://www.rubydoc.info/gems/track_ballast) for individual units.
@@ -45,6 +55,18 @@ require "track_ballast/callable"
45
55
 
46
56
  class MyService
47
57
  extend TrackBallast::Callable
58
+
59
+ # ...
60
+ end
61
+ ```
62
+
63
+ ```ruby
64
+ require "track_ballast/stop_signal"
65
+
66
+ class MyJob < ApplicationJob
67
+ extend TrackBallast::StopSignal
68
+
69
+ # ...
48
70
  end
49
71
  ```
50
72
 
@@ -62,6 +84,8 @@ Please see [the Milestones on GitHub](https://github.com/doximity/track_ballast/
62
84
 
63
85
  ## Development
64
86
 
87
+ You'll need [Redis](https://redis.io/docs/getting-started/) and [Ruby](https://www.ruby-lang.org/en/downloads/) installed. Please ensure both are set up before continuing.
88
+
65
89
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
66
90
 
67
91
  To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
@@ -74,7 +98,7 @@ find spec -name '*_spec.rb' -exec bundle exec rspec {} \;
74
98
 
75
99
  ## Contributing
76
100
 
77
- 1. See [CONTRIBUTING.md](./CONTRIBUTING.md)
101
+ 1. See [CONTRIBUTING.md](https://github.com/doximity/track_ballast/blob/master/CONTRIBUTING.md)
78
102
  2. Fork it ( https://github.com/doximity/track_ballast/fork )
79
103
  3. Create your feature branch (`git checkout -b my-new-feature`)
80
104
  4. Commit your changes (`git commit -am 'Add some feature'`)
@@ -1,3 +1,4 @@
1
1
  require "track_ballast"
2
2
  require "track_ballast/callable"
3
+ require "track_ballast/stop_signal"
3
4
  require "track_ballast/uuid_management"
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "redis"
4
+ require "track_ballast/error"
5
+
6
+ module TrackBallast
7
+ # Raised when Redis access is attempted without a configured Redis connection.
8
+ class NoRedisError < Error; end
9
+
10
+ class << self
11
+ attr_writer :redis
12
+
13
+ # Internal Redis connection for +TrackBallast+.
14
+ #
15
+ # It defaults to the Redis instance configured by the +REDIS_URL+
16
+ # environment variable.
17
+ #
18
+ # @return [Redis] a Redis connection
19
+ def redis
20
+ if @redis
21
+ @redis
22
+ elsif ENV["REDIS_URL"]
23
+ # This will short-circuit to be `@redis` on future runs
24
+ @redis = Redis.new(url: ENV["REDIS_URL"])
25
+ else
26
+ raise NoRedisError, "TrackBallast.redis is not configured"
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,143 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "track_ballast/redis"
4
+
5
+ module TrackBallast
6
+ class StopSignalError < StandardError; end
7
+
8
+ # +StopSignal+ is a module that provides a way to stop a process while it is
9
+ # running.
10
+ #
11
+ # It uses Redis to store the stop signal. Please see +TrackBallast.redis+
12
+ # for more details.
13
+ #
14
+ # When the stop signal is set, the client process will stop the next time the
15
+ # process manually checks the +stopped?+ method.
16
+ #
17
+ # == Usage
18
+ #
19
+ # +StopSignal+ can be used via +extend+ or +include+.
20
+ #
21
+ # === Extend
22
+ #
23
+ # - Extend the module in your class
24
+ # - Call +stopped?+ to check if the stop signal is set, for example: at the
25
+ # beginning of the +perform+ method in a job class.
26
+ # - If desired, add an implementation of the +stop_signal_key+ method. This
27
+ # can be useful for stopping multiple classes with the same stop signal. For
28
+ # example: multiple related jobs. The default implementation is to use the
29
+ # class name.
30
+ #
31
+ # Then, from another process, you can manipulate the stop signal:
32
+ #
33
+ # - Call +YourClass.stop!+ to set the stop signal
34
+ # - Call +YourClass.go!+ to remove the stop signal
35
+ #
36
+ # ==== Example
37
+ #
38
+ # class YourJob < ApplicationJob
39
+ # extend TrackBallast::StopSignal
40
+ #
41
+ # def perform
42
+ # return if self.class.stopped?
43
+ #
44
+ # # Process your job here
45
+ # end
46
+ #
47
+ # # Optional:
48
+ # #
49
+ # # def self.stop_signal_key
50
+ # # "custom_stop_signal_key:stop"
51
+ # # end
52
+ # end
53
+ #
54
+ # === Include
55
+ #
56
+ # - Include the module in your class
57
+ # - Call +stopped?+ to check if the stop signal is set, for example: at the
58
+ # beginning of the +perform+ method in a job class.
59
+ # - If desired, add an implementation of the +stop_signal_key+ method. This
60
+ # can tie the stop signal to a specific instance of the class, as shown in
61
+ # the example below.
62
+ #
63
+ # Then, from another process, you can manipulate the stop signal:
64
+ #
65
+ # - Call +your_model_instance.stop!+ to set the stop signal
66
+ # - Call +your_model_instance.go!+ to remove the stop signal
67
+ #
68
+ # ==== Example
69
+ #
70
+ # class YourModel < ApplicationRecord
71
+ # include TrackBallast::StopSignal
72
+ #
73
+ # # Optional, but recommended for usage via `include`
74
+ # def stop_signal_key
75
+ # "#{self.class.name}:#{id}:stop"
76
+ # end
77
+ # end
78
+ #
79
+ # class YourModelService
80
+ # def initialize(your_model_instance)
81
+ # @your_model_instance = your_model_instance
82
+ # end
83
+ #
84
+ # def call
85
+ # return if your_model_instance.stopped?
86
+ #
87
+ # # Process `your_model_instance` here
88
+ # end
89
+ # end
90
+ #
91
+ module StopSignal
92
+ # Set the stop signal
93
+ #
94
+ # @return [Boolean] +true+ if the stop signal was set
95
+ # @raise [StopSignalError] if an error occurred while setting the stop signal
96
+ def stop!
97
+ redis.set(stop_signal_key, true)
98
+
99
+ true
100
+ rescue Redis::CommandError
101
+ raise StopSignalError
102
+ end
103
+
104
+ # Remove the stop signal
105
+ #
106
+ # @return [Boolean] +true+ if the stop signal was removed
107
+ # @raise [StopSignalError] if an error occurred while removing the stop signal
108
+ def go!
109
+ redis.del(stop_signal_key)
110
+
111
+ true
112
+ rescue Redis::CommandError
113
+ raise StopSignalError
114
+ end
115
+
116
+ # Check if the stop signal is set
117
+ #
118
+ # @raise [StopSignalError] if an error occurred while checking the stop signal
119
+ def stopped?
120
+ redis.exists(stop_signal_key).positive?
121
+ rescue Redis::CommandError
122
+ raise StopSignalError
123
+ end
124
+
125
+ # The key used to store the stop signal.
126
+ #
127
+ # It defaults to the class name plus ":stop".
128
+ #
129
+ # This can be overridden to provide a custom key as described in the
130
+ # +StopSignal+ module documentation.
131
+ #
132
+ # @return [String] the key used to store the stop signal
133
+ def stop_signal_key
134
+ "#{name}:stop"
135
+ end
136
+
137
+ private
138
+
139
+ def redis
140
+ TrackBallast.redis
141
+ end
142
+ end
143
+ end
@@ -1,3 +1,3 @@
1
1
  module TrackBallast
2
- VERSION = "0.1.0"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -27,8 +27,9 @@ Gem::Specification.new do |spec|
27
27
  spec.executables = []
28
28
  spec.require_paths = ["lib"]
29
29
 
30
- spec.add_dependency "activerecord", ">= 6.1", "< 8.0"
31
- spec.add_dependency "activesupport", ">= 6.1", "< 8.0"
30
+ spec.add_dependency "activerecord", ">= 7.0", "< 9.0"
31
+ spec.add_dependency "activesupport", ">= 7.0", "< 9.0"
32
+ spec.add_dependency "redis", ">= 4.8", "< 6.0"
32
33
  spec.add_development_dependency "bundler"
33
34
  spec.add_development_dependency "guard"
34
35
  spec.add_development_dependency "guard-rspec"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: track_ballast
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benjamin Oakes
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-02-12 00:00:00.000000000 Z
11
+ date: 2025-08-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -16,40 +16,60 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '6.1'
19
+ version: '7.0'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '8.0'
22
+ version: '9.0'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: '6.1'
29
+ version: '7.0'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '8.0'
32
+ version: '9.0'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: activesupport
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - ">="
38
38
  - !ruby/object:Gem::Version
39
- version: '6.1'
39
+ version: '7.0'
40
40
  - - "<"
41
41
  - !ruby/object:Gem::Version
42
- version: '8.0'
42
+ version: '9.0'
43
43
  type: :runtime
44
44
  prerelease: false
45
45
  version_requirements: !ruby/object:Gem::Requirement
46
46
  requirements:
47
47
  - - ">="
48
48
  - !ruby/object:Gem::Version
49
- version: '6.1'
49
+ version: '7.0'
50
50
  - - "<"
51
51
  - !ruby/object:Gem::Version
52
- version: '8.0'
52
+ version: '9.0'
53
+ - !ruby/object:Gem::Dependency
54
+ name: redis
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '4.8'
60
+ - - "<"
61
+ - !ruby/object:Gem::Version
62
+ version: '6.0'
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '4.8'
70
+ - - "<"
71
+ - !ruby/object:Gem::Version
72
+ version: '6.0'
53
73
  - !ruby/object:Gem::Dependency
54
74
  name: bundler
55
75
  requirement: !ruby/object:Gem::Requirement
@@ -215,6 +235,8 @@ files:
215
235
  - lib/track_ballast/callable.rb
216
236
  - lib/track_ballast/error.rb
217
237
  - lib/track_ballast/logger.rb
238
+ - lib/track_ballast/redis.rb
239
+ - lib/track_ballast/stop_signal.rb
218
240
  - lib/track_ballast/uuid_management.rb
219
241
  - lib/track_ballast/version.rb
220
242
  - track_ballast.gemspec