diff --git a/Gemfile.lock b/Gemfile.lock index 471dbe5..2634697 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,12 +1,13 @@ PATH remote: . specs: - super_spreader (0.2.1) + super_spreader (1.0.0.beta) activejob (>= 6.1, < 8.0) activemodel (>= 6.1, < 8.0) activerecord (>= 6.1, < 8.0) activesupport (>= 6.1, < 8.0) redis (>= 4.8, < 6.0) + track_ballast (>= 0.2.0.beta1) GEM remote: https://rubygems.org/ @@ -179,6 +180,10 @@ GEM lint_roller (~> 1.1) rubocop-performance (~> 1.19.1) thor (1.3.0) + track_ballast (0.2.0.beta1) + activerecord (>= 6.1, < 8.0) + activesupport (>= 6.1, < 8.0) + redis (>= 4.8, < 6.0) tzinfo (2.0.6) concurrent-ruby (~> 1.0) unicode-display_width (2.5.0) diff --git a/lib/super_spreader.rb b/lib/super_spreader.rb index 0b4c2c9..7902aa2 100644 --- a/lib/super_spreader.rb +++ b/lib/super_spreader.rb @@ -9,12 +9,27 @@ require "super_spreader/scheduler_job" require "super_spreader/spread_tracker" require "super_spreader/spreader" -require "super_spreader/stop_signal" +require "track_ballast/stop_signal" module SuperSpreader class Error < StandardError; end class << self attr_accessor :logger, :redis + + def redis=(redis_instance) + @redis = redis_instance + TrackBallast.redis = redis_instance + @redis + end + + # @!visibility private + def const_missing(const_name) + super unless const_name == :StopSignal + + warn "DEPRECATION WARNING: the class SuperSpreader::StopSignal is deprecated. " \ + "Use TrackBallast::StopSignal instead." + TrackBallast::StopSignal + end end end diff --git a/lib/super_spreader/scheduler_job.rb b/lib/super_spreader/scheduler_job.rb index 3b45734..bf5baab 100644 --- a/lib/super_spreader/scheduler_job.rb +++ b/lib/super_spreader/scheduler_job.rb @@ -4,11 +4,11 @@ require "json" require "super_spreader/scheduler_config" require "super_spreader/spreader" -require "super_spreader/stop_signal" +require "track_ballast/stop_signal" module SuperSpreader class SchedulerJob < ActiveJob::Base - extend StopSignal + extend TrackBallast::StopSignal def perform return if self.class.stopped? diff --git a/lib/super_spreader/stop_signal.rb b/lib/super_spreader/stop_signal.rb deleted file mode 100644 index 2aab821..0000000 --- a/lib/super_spreader/stop_signal.rb +++ /dev/null @@ -1,35 +0,0 @@ -# frozen_string_literal: true - -require "redis" - -module SuperSpreader - # @deprecated Please use TrackBallast::StopSignal instead - module StopSignal - # @deprecated Please use {TrackBallast::StopSignal.stop!} instead - def stop! - warn "DEPRECATION WARNING: the class SuperSpreader::StopSignal is deprecated and will be removed in v1.0. " \ - "Use TrackBallast::StopSignal instead." - redis.set(stop_key, true) - end - - # @deprecated Please use {TrackBallast::StopSignal.go!} instead - def go! - redis.del(stop_key) - end - - # @deprecated Please use {TrackBallast::StopSignal.stopped?} instead - def stopped? - redis.exists(stop_key).positive? - end - - private - - def redis - SuperSpreader.redis - end - - def stop_key - "#{name}:stop" - end - end -end diff --git a/lib/super_spreader/version.rb b/lib/super_spreader/version.rb index fd582fc..e71d702 100644 --- a/lib/super_spreader/version.rb +++ b/lib/super_spreader/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module SuperSpreader - VERSION = "0.2.1" + VERSION = "1.0.0.beta" end diff --git a/spec/stop_signal_spec.rb b/spec/stop_signal_spec.rb deleted file mode 100644 index 31fe268..0000000 --- a/spec/stop_signal_spec.rb +++ /dev/null @@ -1,32 +0,0 @@ -# frozen_string_literal: true - -require "spec_helper" - -RSpec.describe SuperSpreader::StopSignal do - it "has a lifecycle that allows stopping a job" do - fake_job = Class.new do - extend SuperSpreader::StopSignal - end - - # Default - expect(fake_job.stopped?).to eq(false) - - fake_job.stop! - - expect(fake_job.stopped?).to eq(true) - - # Idempotent - fake_job.stop! - - expect(fake_job.stopped?).to eq(true) - - fake_job.go! - - expect(fake_job.stopped?).to eq(false) - - # Idempotent - fake_job.go! - - expect(fake_job.stopped?).to eq(false) - end -end diff --git a/spec/super_spreader_spec.rb b/spec/super_spreader_spec.rb index c1d390b..880a987 100644 --- a/spec/super_spreader_spec.rb +++ b/spec/super_spreader_spec.rb @@ -6,4 +6,8 @@ it "has a version number" do expect(SuperSpreader::VERSION).not_to be nil end + + it "allows referencing StopSignal while transitioning to TrackBallast::StopSignal" do + expect(SuperSpreader::StopSignal).to be TrackBallast::StopSignal + end end diff --git a/spec/support/example_backfill_job.rb b/spec/support/example_backfill_job.rb index b667f83..c1edbbd 100644 --- a/spec/support/example_backfill_job.rb +++ b/spec/support/example_backfill_job.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +require "track_ballast/stop_signal" + # This class is an example job that uses the interface that SuperSpreader # expects. While this job is for backfilling as an example, any problem # that can be subdivided into small batches can be implemented. @@ -9,7 +11,7 @@ class ExampleBackfillJob < ActiveJob::Base # This provides support for stopping the job in an emergency. Optional, but # highly recommended. - extend SuperSpreader::StopSignal + extend TrackBallast::StopSignal # This is the model class that will be used when tracking the spread of jobs. # It is expected to be an ActiveRecord class. diff --git a/super_spreader.gemspec b/super_spreader.gemspec index 9bac411..a3d42ed 100644 --- a/super_spreader.gemspec +++ b/super_spreader.gemspec @@ -32,6 +32,7 @@ Gem::Specification.new do |spec| spec.add_dependency "activerecord", ">= 6.1", "< 8.0" spec.add_dependency "activesupport", ">= 6.1", "< 8.0" spec.add_dependency "redis", ">= 4.8", "< 6.0" + spec.add_dependency "track_ballast", ">= 0.2.0.beta1" spec.add_development_dependency "bundler" spec.add_development_dependency "factory_bot" spec.add_development_dependency "guard"