stepper_motor 0.1.7 → 0.1.8

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.
Files changed (96) hide show
  1. checksums.yaml +4 -4
  2. data/.github/dependabot.yml +12 -0
  3. data/.github/workflows/ci.yml +51 -0
  4. data/CHANGELOG.md +77 -2
  5. data/Gemfile +11 -0
  6. data/README.md +13 -374
  7. data/Rakefile +21 -3
  8. data/bin/test +5 -0
  9. data/lib/generators/install_generator.rb +6 -1
  10. data/lib/generators/stepper_motor_migration_003.rb.erb +6 -0
  11. data/lib/generators/stepper_motor_migration_004.rb.erb +26 -0
  12. data/lib/stepper_motor/forward_scheduler.rb +8 -4
  13. data/lib/stepper_motor/journey/flow_control.rb +58 -0
  14. data/lib/stepper_motor/journey/recovery.rb +34 -0
  15. data/lib/stepper_motor/journey.rb +85 -84
  16. data/lib/stepper_motor/perform_step_job_v2.rb +2 -2
  17. data/lib/stepper_motor/recover_stuck_journeys_job_v1.rb +3 -1
  18. data/lib/stepper_motor/step.rb +70 -5
  19. data/lib/stepper_motor/version.rb +1 -1
  20. data/lib/stepper_motor.rb +0 -1
  21. data/lib/tasks/stepper_motor_tasks.rake +8 -0
  22. data/manual/MANUAL.md +538 -0
  23. data/rbi/stepper_motor.rbi +459 -0
  24. data/sig/stepper_motor.rbs +406 -3
  25. data/stepper_motor.gemspec +49 -0
  26. data/test/dummy/Rakefile +8 -0
  27. data/test/dummy/app/assets/stylesheets/application.css +1 -0
  28. data/test/dummy/app/controllers/application_controller.rb +6 -0
  29. data/test/dummy/app/helpers/application_helper.rb +4 -0
  30. data/test/dummy/app/jobs/application_job.rb +9 -0
  31. data/test/dummy/app/mailers/application_mailer.rb +6 -0
  32. data/test/dummy/app/models/application_record.rb +5 -0
  33. data/test/dummy/app/views/layouts/application.html.erb +27 -0
  34. data/test/dummy/app/views/layouts/mailer.html.erb +13 -0
  35. data/test/dummy/app/views/layouts/mailer.text.erb +1 -0
  36. data/test/dummy/app/views/pwa/manifest.json.erb +22 -0
  37. data/test/dummy/app/views/pwa/service-worker.js +26 -0
  38. data/test/dummy/bin/dev +2 -0
  39. data/test/dummy/bin/rails +4 -0
  40. data/test/dummy/bin/rake +4 -0
  41. data/test/dummy/bin/setup +34 -0
  42. data/test/dummy/config/application.rb +28 -0
  43. data/test/dummy/config/boot.rb +7 -0
  44. data/test/dummy/config/cable.yml +10 -0
  45. data/test/dummy/config/database.yml +32 -0
  46. data/test/dummy/config/environment.rb +7 -0
  47. data/test/dummy/config/environments/development.rb +71 -0
  48. data/test/dummy/config/environments/production.rb +91 -0
  49. data/test/dummy/config/environments/test.rb +55 -0
  50. data/test/dummy/config/initializers/content_security_policy.rb +27 -0
  51. data/test/dummy/config/initializers/filter_parameter_logging.rb +10 -0
  52. data/test/dummy/config/initializers/inflections.rb +18 -0
  53. data/test/dummy/config/initializers/stepper_motor.rb +3 -0
  54. data/test/dummy/config/locales/en.yml +31 -0
  55. data/test/dummy/config/puma.rb +40 -0
  56. data/test/dummy/config/routes.rb +16 -0
  57. data/test/dummy/config/storage.yml +34 -0
  58. data/test/dummy/config.ru +8 -0
  59. data/test/dummy/db/migrate/20250520094921_stepper_motor_migration_001.rb +38 -0
  60. data/test/dummy/db/migrate/20250520094922_stepper_motor_migration_002.rb +8 -0
  61. data/test/dummy/db/migrate/20250522212312_stepper_motor_migration_003.rb +7 -0
  62. data/test/dummy/db/migrate/20250525110812_stepper_motor_migration_004.rb +28 -0
  63. data/test/dummy/db/schema.rb +37 -0
  64. data/test/dummy/public/400.html +114 -0
  65. data/test/dummy/public/404.html +114 -0
  66. data/test/dummy/public/406-unsupported-browser.html +114 -0
  67. data/test/dummy/public/422.html +114 -0
  68. data/test/dummy/public/500.html +114 -0
  69. data/test/dummy/public/icon.png +0 -0
  70. data/test/dummy/public/icon.svg +3 -0
  71. data/test/side_effects_helper.rb +67 -0
  72. data/test/stepper_motor/cyclic_scheduler_test.rb +77 -0
  73. data/{spec/stepper_motor/forward_scheduler_spec.rb → test/stepper_motor/forward_scheduler_test.rb} +9 -10
  74. data/test/stepper_motor/journey/exception_handling_test.rb +89 -0
  75. data/test/stepper_motor/journey/flow_control_test.rb +78 -0
  76. data/test/stepper_motor/journey/idempotency_test.rb +65 -0
  77. data/test/stepper_motor/journey/step_definition_test.rb +187 -0
  78. data/test/stepper_motor/journey/uniqueness_test.rb +48 -0
  79. data/test/stepper_motor/journey_test.rb +352 -0
  80. data/{spec/stepper_motor/recover_stuck_journeys_job_spec.rb → test/stepper_motor/recover_stuck_journeys_job_test.rb} +14 -14
  81. data/{spec/stepper_motor/recovery_spec.rb → test/stepper_motor/recovery_test.rb} +27 -27
  82. data/test/stepper_motor/test_helper_test.rb +44 -0
  83. data/test/stepper_motor_test.rb +9 -0
  84. data/test/test_helper.rb +46 -0
  85. metadata +120 -24
  86. data/.rspec +0 -3
  87. data/.ruby-version +0 -1
  88. data/.standard.yml +0 -4
  89. data/.yardopts +0 -1
  90. data/spec/helpers/side_effects.rb +0 -85
  91. data/spec/spec_helper.rb +0 -90
  92. data/spec/stepper_motor/cyclic_scheduler_spec.rb +0 -68
  93. data/spec/stepper_motor/generator_spec.rb +0 -16
  94. data/spec/stepper_motor/journey_spec.rb +0 -401
  95. data/spec/stepper_motor/test_helper_spec.rb +0 -48
  96. data/spec/stepper_motor_spec.rb +0 -7
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "boot"
4
+
5
+ require "rails/all"
6
+
7
+ # Require the gems listed in Gemfile, including any gems
8
+ # you've limited to :test, :development, or :production.
9
+ Bundler.require(*Rails.groups)
10
+
11
+ module Dummy
12
+ class Application < Rails::Application
13
+ config.load_defaults Rails::VERSION::STRING.to_f
14
+
15
+ # Please, add to the `ignore` list any other `lib` subdirectories that do
16
+ # not contain `.rb` files, or that should not be reloaded or eager loaded.
17
+ # Common ones are `templates`, `generators`, or `middleware`, for example.
18
+ config.autoload_lib(ignore: %w[assets tasks])
19
+
20
+ # Configuration for the application, engines, and railties goes here.
21
+ #
22
+ # These settings can be overridden in specific environments using the files
23
+ # in config/environments, which are processed later.
24
+ #
25
+ # config.time_zone = "Central Time (US & Canada)"
26
+ # config.eager_load_paths << Rails.root.join("extras")
27
+ end
28
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Set up gems listed in the Gemfile.
4
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../../Gemfile", __dir__)
5
+
6
+ require "bundler/setup" if File.exist?(ENV["BUNDLE_GEMFILE"])
7
+ $LOAD_PATH.unshift File.expand_path("../../../lib", __dir__)
@@ -0,0 +1,10 @@
1
+ development:
2
+ adapter: async
3
+
4
+ test:
5
+ adapter: test
6
+
7
+ production:
8
+ adapter: redis
9
+ url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %>
10
+ channel_prefix: dummy_production
@@ -0,0 +1,32 @@
1
+ # SQLite. Versions 3.8.0 and up are supported.
2
+ # gem install sqlite3
3
+ #
4
+ # Ensure the SQLite 3 gem is defined in your Gemfile
5
+ # gem "sqlite3"
6
+ #
7
+ default: &default
8
+ adapter: sqlite3
9
+ pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
10
+ timeout: 5000
11
+
12
+ development:
13
+ <<: *default
14
+ database: storage/development.sqlite3
15
+
16
+ # Warning: The database defined as "test" will be erased and
17
+ # re-generated from your development database when you run "rake".
18
+ # Do not set this db to the same as development or production.
19
+ test:
20
+ <<: *default
21
+ database: storage/test.sqlite3
22
+
23
+
24
+ # SQLite3 write its data on the local filesystem, as such it requires
25
+ # persistent disks. If you are deploying to a managed service, you should
26
+ # make sure it provides disk persistence, as many don't.
27
+ #
28
+ # Similarly, if you deploy your application as a Docker container, you must
29
+ # ensure the database is located in a persisted volume.
30
+ production:
31
+ <<: *default
32
+ # database: path/to/persistent/storage/production.sqlite3
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Load the Rails application.
4
+ require_relative "application"
5
+
6
+ # Initialize the Rails application.
7
+ Rails.application.initialize!
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/core_ext/integer/time"
4
+
5
+ Rails.application.configure do
6
+ # Settings specified here will take precedence over those in config/application.rb.
7
+
8
+ # Make code changes take effect immediately without server restart.
9
+ config.enable_reloading = true
10
+
11
+ # Do not eager load code on boot.
12
+ config.eager_load = false
13
+
14
+ # Show full error reports.
15
+ config.consider_all_requests_local = true
16
+
17
+ # Enable server timing.
18
+ config.server_timing = true
19
+
20
+ # Enable/disable Action Controller caching. By default Action Controller caching is disabled.
21
+ # Run rails dev:cache to toggle Action Controller caching.
22
+ if Rails.root.join("tmp/caching-dev.txt").exist?
23
+ config.action_controller.perform_caching = true
24
+ config.action_controller.enable_fragment_cache_logging = true
25
+ config.public_file_server.headers = {"cache-control" => "public, max-age=#{2.days.to_i}"}
26
+ else
27
+ config.action_controller.perform_caching = false
28
+ end
29
+
30
+ # Change to :null_store to avoid any caching.
31
+ config.cache_store = :memory_store
32
+
33
+ # Store uploaded files on the local file system (see config/storage.yml for options).
34
+ config.active_storage.service = :local
35
+
36
+ # Don't care if the mailer can't send.
37
+ config.action_mailer.raise_delivery_errors = false
38
+
39
+ # Make template changes take effect immediately.
40
+ config.action_mailer.perform_caching = false
41
+
42
+ # Set localhost to be used by links generated in mailer templates.
43
+ config.action_mailer.default_url_options = {host: "localhost", port: 3000}
44
+
45
+ # Print deprecation notices to the Rails logger.
46
+ config.active_support.deprecation = :log
47
+
48
+ # Raise an error on page load if there are pending migrations.
49
+ config.active_record.migration_error = :page_load
50
+
51
+ # Highlight code that triggered database queries in logs.
52
+ config.active_record.verbose_query_logs = true
53
+
54
+ # Append comments with runtime information tags to SQL queries in logs.
55
+ config.active_record.query_log_tags_enabled = true
56
+
57
+ # Highlight code that enqueued background job in logs.
58
+ config.active_job.verbose_enqueue_logs = true
59
+
60
+ # Raises error for missing translations.
61
+ # config.i18n.raise_on_missing_translations = true
62
+
63
+ # Annotate rendered view with file names.
64
+ config.action_view.annotate_rendered_view_with_filenames = true
65
+
66
+ # Uncomment if you wish to allow Action Cable access from any origin.
67
+ # config.action_cable.disable_request_forgery_protection = true
68
+
69
+ # Raise error when a before_action's only/except options reference missing actions.
70
+ config.action_controller.raise_on_missing_callback_actions = true
71
+ end
@@ -0,0 +1,91 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/core_ext/integer/time"
4
+
5
+ Rails.application.configure do
6
+ # Settings specified here will take precedence over those in config/application.rb.
7
+
8
+ # Code is not reloaded between requests.
9
+ config.enable_reloading = false
10
+
11
+ # Eager load code on boot for better performance and memory savings (ignored by Rake tasks).
12
+ config.eager_load = true
13
+
14
+ # Full error reports are disabled.
15
+ config.consider_all_requests_local = false
16
+
17
+ # Turn on fragment caching in view templates.
18
+ config.action_controller.perform_caching = true
19
+
20
+ # Cache assets for far-future expiry since they are all digest stamped.
21
+ config.public_file_server.headers = {"cache-control" => "public, max-age=#{1.year.to_i}"}
22
+
23
+ # Enable serving of images, stylesheets, and JavaScripts from an asset server.
24
+ # config.asset_host = "http://assets.example.com"
25
+
26
+ # Store uploaded files on the local file system (see config/storage.yml for options).
27
+ config.active_storage.service = :local
28
+
29
+ # Assume all access to the app is happening through a SSL-terminating reverse proxy.
30
+ config.assume_ssl = true
31
+
32
+ # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
33
+ config.force_ssl = true
34
+
35
+ # Skip http-to-https redirect for the default health check endpoint.
36
+ # config.ssl_options = { redirect: { exclude: ->(request) { request.path == "/up" } } }
37
+
38
+ # Log to STDOUT with the current request id as a default log tag.
39
+ config.log_tags = [:request_id]
40
+ config.logger = ActiveSupport::TaggedLogging.logger($stdout)
41
+
42
+ # Change to "debug" to log everything (including potentially personally-identifiable information!)
43
+ config.log_level = ENV.fetch("RAILS_LOG_LEVEL", "info")
44
+
45
+ # Prevent health checks from clogging up the logs.
46
+ config.silence_healthcheck_path = "/up"
47
+
48
+ # Don't log any deprecations.
49
+ config.active_support.report_deprecations = false
50
+
51
+ # Replace the default in-process memory cache store with a durable alternative.
52
+ # config.cache_store = :mem_cache_store
53
+
54
+ # Replace the default in-process and non-durable queuing backend for Active Job.
55
+ # config.active_job.queue_adapter = :resque
56
+
57
+ # Ignore bad email addresses and do not raise email delivery errors.
58
+ # Set this to true and configure the email server for immediate delivery to raise delivery errors.
59
+ # config.action_mailer.raise_delivery_errors = false
60
+
61
+ # Set host to be used by links generated in mailer templates.
62
+ config.action_mailer.default_url_options = {host: "example.com"}
63
+
64
+ # Specify outgoing SMTP server. Remember to add smtp/* credentials via rails credentials:edit.
65
+ # config.action_mailer.smtp_settings = {
66
+ # user_name: Rails.application.credentials.dig(:smtp, :user_name),
67
+ # password: Rails.application.credentials.dig(:smtp, :password),
68
+ # address: "smtp.example.com",
69
+ # port: 587,
70
+ # authentication: :plain
71
+ # }
72
+
73
+ # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
74
+ # the I18n.default_locale when a translation cannot be found).
75
+ config.i18n.fallbacks = true
76
+
77
+ # Do not dump schema after migrations.
78
+ config.active_record.dump_schema_after_migration = false
79
+
80
+ # Only use :id for inspections in production.
81
+ config.active_record.attributes_for_inspect = [:id]
82
+
83
+ # Enable DNS rebinding protection and other `Host` header attacks.
84
+ # config.hosts = [
85
+ # "example.com", # Allow requests from example.com
86
+ # /.*\.example\.com/ # Allow requests from subdomains like `www.example.com`
87
+ # ]
88
+ #
89
+ # Skip DNS rebinding protection for the default health check endpoint.
90
+ # config.host_authorization = { exclude: ->(request) { request.path == "/up" } }
91
+ end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ # The test environment is used exclusively to run your application's
4
+ # test suite. You never need to work with it otherwise. Remember that
5
+ # your test database is "scratch space" for the test suite and is wiped
6
+ # and recreated between test runs. Don't rely on the data there!
7
+
8
+ Rails.application.configure do
9
+ # Settings specified here will take precedence over those in config/application.rb.
10
+
11
+ # While tests run files are not watched, reloading is not necessary.
12
+ config.enable_reloading = false
13
+
14
+ # Eager loading loads your entire application. When running a single test locally,
15
+ # this is usually not necessary, and can slow down your test suite. However, it's
16
+ # recommended that you enable it in continuous integration systems to ensure eager
17
+ # loading is working properly before deploying your code.
18
+ config.eager_load = ENV["CI"].present?
19
+
20
+ # Configure public file server for tests with cache-control for performance.
21
+ config.public_file_server.headers = {"cache-control" => "public, max-age=3600"}
22
+
23
+ # Show full error reports.
24
+ config.consider_all_requests_local = true
25
+ config.cache_store = :null_store
26
+
27
+ # Render exception templates for rescuable exceptions and raise for other exceptions.
28
+ config.action_dispatch.show_exceptions = :rescuable
29
+
30
+ # Disable request forgery protection in test environment.
31
+ config.action_controller.allow_forgery_protection = false
32
+
33
+ # Store uploaded files on the local file system in a temporary directory.
34
+ config.active_storage.service = :test
35
+
36
+ # Tell Action Mailer not to deliver emails to the real world.
37
+ # The :test delivery method accumulates sent emails in the
38
+ # ActionMailer::Base.deliveries array.
39
+ config.action_mailer.delivery_method = :test
40
+
41
+ # Set host to be used by links generated in mailer templates.
42
+ config.action_mailer.default_url_options = {host: "example.com"}
43
+
44
+ # Print deprecation notices to the stderr.
45
+ config.active_support.deprecation = :stderr
46
+
47
+ # Raises error for missing translations.
48
+ # config.i18n.raise_on_missing_translations = true
49
+
50
+ # Annotate rendered view with file names.
51
+ # config.action_view.annotate_rendered_view_with_filenames = true
52
+
53
+ # Raise error when a before_action's only/except options reference missing actions.
54
+ config.action_controller.raise_on_missing_callback_actions = true
55
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Be sure to restart your server when you modify this file.
4
+
5
+ # Define an application-wide content security policy.
6
+ # See the Securing Rails Applications Guide for more information:
7
+ # https://guides.rubyonrails.org/security.html#content-security-policy-header
8
+
9
+ # Rails.application.configure do
10
+ # config.content_security_policy do |policy|
11
+ # policy.default_src :self, :https
12
+ # policy.font_src :self, :https, :data
13
+ # policy.img_src :self, :https, :data
14
+ # policy.object_src :none
15
+ # policy.script_src :self, :https
16
+ # policy.style_src :self, :https
17
+ # # Specify URI for violation reports
18
+ # # policy.report_uri "/csp-violation-report-endpoint"
19
+ # end
20
+ #
21
+ # # Generate session nonces for permitted importmap, inline scripts, and inline styles.
22
+ # config.content_security_policy_nonce_generator = ->(request) { request.session.id.to_s }
23
+ # config.content_security_policy_nonce_directives = %w(script-src style-src)
24
+ #
25
+ # # Report violations without enforcing the policy.
26
+ # # config.content_security_policy_report_only = true
27
+ # end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Be sure to restart your server when you modify this file.
4
+
5
+ # Configure parameters to be partially matched (e.g. passw matches password) and filtered from the log file.
6
+ # Use this to limit dissemination of sensitive information.
7
+ # See the ActiveSupport::ParameterFilter documentation for supported notations and behaviors.
8
+ Rails.application.config.filter_parameters += [
9
+ :passw, :email, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn, :cvv, :cvc
10
+ ]
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Be sure to restart your server when you modify this file.
4
+
5
+ # Add new inflection rules using the following format. Inflections
6
+ # are locale specific, and you may define rules for as many different
7
+ # locales as you wish. All of these examples are active by default:
8
+ # ActiveSupport::Inflector.inflections(:en) do |inflect|
9
+ # inflect.plural /^(ox)$/i, "\\1en"
10
+ # inflect.singular /^(ox)en/i, "\\1"
11
+ # inflect.irregular "person", "people"
12
+ # inflect.uncountable %w( fish sheep )
13
+ # end
14
+
15
+ # These inflection rules are supported but not enabled by default:
16
+ # ActiveSupport::Inflector.inflections(:en) do |inflect|
17
+ # inflect.acronym "RESTful"
18
+ # end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ StepperMotor.scheduler = StepperMotor::ForwardScheduler.new
@@ -0,0 +1,31 @@
1
+ # Files in the config/locales directory are used for internationalization and
2
+ # are automatically loaded by Rails. If you want to use locales other than
3
+ # English, add the necessary files in this directory.
4
+ #
5
+ # To use the locales, use `I18n.t`:
6
+ #
7
+ # I18n.t "hello"
8
+ #
9
+ # In views, this is aliased to just `t`:
10
+ #
11
+ # <%= t("hello") %>
12
+ #
13
+ # To use a different locale, set it with `I18n.locale`:
14
+ #
15
+ # I18n.locale = :es
16
+ #
17
+ # This would use the information in config/locales/es.yml.
18
+ #
19
+ # To learn more about the API, please read the Rails Internationalization guide
20
+ # at https://guides.rubyonrails.org/i18n.html.
21
+ #
22
+ # Be aware that YAML interprets the following case-insensitive strings as
23
+ # booleans: `true`, `false`, `on`, `off`, `yes`, `no`. Therefore, these strings
24
+ # must be quoted to be interpreted as strings. For example:
25
+ #
26
+ # en:
27
+ # "yes": yup
28
+ # enabled: "ON"
29
+
30
+ en:
31
+ hello: "Hello world"
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This configuration file will be evaluated by Puma. The top-level methods that
4
+ # are invoked here are part of Puma's configuration DSL. For more information
5
+ # about methods provided by the DSL, see https://puma.io/puma/Puma/DSL.html.
6
+ #
7
+ # Puma starts a configurable number of processes (workers) and each process
8
+ # serves each request in a thread from an internal thread pool.
9
+ #
10
+ # You can control the number of workers using ENV["WEB_CONCURRENCY"]. You
11
+ # should only set this value when you want to run 2 or more workers. The
12
+ # default is already 1.
13
+ #
14
+ # The ideal number of threads per worker depends both on how much time the
15
+ # application spends waiting for IO operations and on how much you wish to
16
+ # prioritize throughput over latency.
17
+ #
18
+ # As a rule of thumb, increasing the number of threads will increase how much
19
+ # traffic a given process can handle (throughput), but due to CRuby's
20
+ # Global VM Lock (GVL) it has diminishing returns and will degrade the
21
+ # response time (latency) of the application.
22
+ #
23
+ # The default is set to 3 threads as it's deemed a decent compromise between
24
+ # throughput and latency for the average Rails application.
25
+ #
26
+ # Any libraries that use a connection pool or another resource pool should
27
+ # be configured to provide at least as many connections as the number of
28
+ # threads. This includes Active Record's `pool` parameter in `database.yml`.
29
+ threads_count = ENV.fetch("RAILS_MAX_THREADS", 3)
30
+ threads threads_count, threads_count
31
+
32
+ # Specifies the `port` that Puma will listen on to receive requests; default is 3000.
33
+ port ENV.fetch("PORT", 3000)
34
+
35
+ # Allow puma to be restarted by `bin/rails restart` command.
36
+ plugin :tmp_restart
37
+
38
+ # Specify the PID file. Defaults to tmp/pids/server.pid in development.
39
+ # In other environments, only set the PID file if requested.
40
+ pidfile ENV["PIDFILE"] if ENV["PIDFILE"]
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ Rails.application.routes.draw do
4
+ # Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html
5
+
6
+ # Reveal health status on /up that returns 200 if the app boots with no exceptions, otherwise 500.
7
+ # Can be used by load balancers and uptime monitors to verify that the app is live.
8
+ get "up" => "rails/health#show", :as => :rails_health_check
9
+
10
+ # Render dynamic PWA files from app/views/pwa/* (remember to link manifest in application.html.erb)
11
+ # get "manifest" => "rails/pwa#manifest", as: :pwa_manifest
12
+ # get "service-worker" => "rails/pwa#service_worker", as: :pwa_service_worker
13
+
14
+ # Defines the root path route ("/")
15
+ # root "posts#index"
16
+ end
@@ -0,0 +1,34 @@
1
+ test:
2
+ service: Disk
3
+ root: <%= Rails.root.join("tmp/storage") %>
4
+
5
+ local:
6
+ service: Disk
7
+ root: <%= Rails.root.join("storage") %>
8
+
9
+ # Use bin/rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key)
10
+ # amazon:
11
+ # service: S3
12
+ # access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %>
13
+ # secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %>
14
+ # region: us-east-1
15
+ # bucket: your_own_bucket-<%= Rails.env %>
16
+
17
+ # Remember not to checkin your GCS keyfile to a repository
18
+ # google:
19
+ # service: GCS
20
+ # project: your_project
21
+ # credentials: <%= Rails.root.join("path/to/gcs.keyfile") %>
22
+ # bucket: your_own_bucket-<%= Rails.env %>
23
+
24
+ # Use bin/rails credentials:edit to set the Azure Storage secret (as azure_storage:storage_access_key)
25
+ # microsoft:
26
+ # service: AzureStorage
27
+ # storage_account_name: your_account_name
28
+ # storage_access_key: <%= Rails.application.credentials.dig(:azure_storage, :storage_access_key) %>
29
+ # container: your_container_name-<%= Rails.env %>
30
+
31
+ # mirror:
32
+ # service: Mirror
33
+ # primary: local
34
+ # mirrors: [ amazon, google, microsoft ]
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This file is used by Rack-based servers to start the application.
4
+
5
+ require_relative "config/environment"
6
+
7
+ run Rails.application
8
+ Rails.application.load_server
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ class StepperMotorMigration001 < ActiveRecord::Migration[7.2]
4
+ def change
5
+ create_table :stepper_motor_journeys do |t|
6
+ t.string :type, null: false, index: true
7
+ t.string :state, default: "ready"
8
+ t.string :hero_type, null: true
9
+
10
+ t.bigint :hero_id
11
+
12
+ t.boolean :allow_multiple, default: false
13
+ t.string :previous_step_name
14
+ t.string :next_step_name
15
+ t.datetime :next_step_to_be_performed_at
16
+ t.bigint :steps_entered, default: 0, null: false
17
+ t.bigint :steps_completed, default: 0, null: false
18
+ t.timestamps
19
+ end
20
+ # Foreign key needs to be indexed for rapid lookups of journeys for a specific hero
21
+ add_index :stepper_motor_journeys, [:hero_type, :hero_id]
22
+
23
+ # An index is needed on the type/hero as well to check whether there is a journey
24
+ # for a specific hero of a specific class
25
+ add_index :stepper_motor_journeys, [:type, :hero_type, :hero_id]
26
+
27
+ # A unique index prevents multiple journeys of the same type from being created for a particular hero
28
+ quoted_false = connection.quote(false)
29
+ add_index :stepper_motor_journeys, [:type, :hero_id, :hero_type], where: "allow_multiple = '#{quoted_false}' AND state IN ('ready', 'performing')", unique: true, name: :one_per_hero_index
30
+
31
+ # An index is also needed for cleaning up finished and canceled journeys quickly
32
+ # for a specific hero of a specific class
33
+ add_index :stepper_motor_journeys, [:updated_at], where: "state = 'canceled' OR state = 'finished'"
34
+
35
+ # An extra index is needed to speed up select-to-perform in case of central scheduling
36
+ add_index :stepper_motor_journeys, [:next_step_to_be_performed_at], where: "state = 'ready'"
37
+ end
38
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ class StepperMotorMigration002 < ActiveRecord::Migration[7.2]
4
+ def change
5
+ # An index is needed to recover stuck journeys
6
+ add_index :stepper_motor_journeys, [:updated_at], name: "stuck_journeys_index", where: "state = 'performing'"
7
+ end
8
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ class StepperMotorMigration003 < ActiveRecord::Migration[7.2]
4
+ def change
5
+ add_column :stepper_motor_journeys, :idempotency_key, :string, null: true
6
+ end
7
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ class StepperMotorMigration004 < ActiveRecord::Migration[7.2]
4
+ def up
5
+ quoted_false = connection.quote(false)
6
+ add_index :stepper_motor_journeys, [:type, :hero_id, :hero_type],
7
+ where: "allow_multiple = '#{quoted_false}' AND state IN ('ready', 'performing', 'paused')",
8
+ unique: true,
9
+ name: :idx_journeys_one_per_hero_with_paused
10
+
11
+ # Remove old indexes that only include 'ready' state
12
+ remove_index :stepper_motor_journeys, [:next_step_to_be_performed_at], where: "state = 'ready'"
13
+ remove_index :stepper_motor_journeys, [:type, :hero_id, :hero_type], name: :one_per_hero_index, where: "allow_multiple = '0' AND state IN ('ready', 'performing')"
14
+ end
15
+
16
+ def down
17
+ # Recreate old indexes
18
+ add_index :stepper_motor_journeys, [:next_step_to_be_performed_at], where: "state = 'ready'"
19
+ quoted_false = connection.quote(false)
20
+ add_index :stepper_motor_journeys, [:type, :hero_id, :hero_type],
21
+ where: "allow_multiple = '#{quoted_false}' AND state IN ('ready', 'performing')",
22
+ unique: true,
23
+ name: :one_per_hero_index
24
+
25
+ # Remove new indexes
26
+ remove_index :stepper_motor_journeys, name: :idx_journeys_one_per_hero_with_paused
27
+ end
28
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This file is auto-generated from the current state of the database. Instead
4
+ # of editing this file, please use the migrations feature of Active Record to
5
+ # incrementally modify your database, and then regenerate this schema definition.
6
+ #
7
+ # This file is the source Rails uses to define your schema when running `bin/rails
8
+ # db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to
9
+ # be faster and is potentially less error prone than running all of your
10
+ # migrations from scratch. Old migrations may fail to apply correctly if those
11
+ # migrations use external dependencies or application code.
12
+ #
13
+ # It's strongly recommended that you check this file into your version control system.
14
+
15
+ ActiveRecord::Schema[7.2].define(version: 2025_05_25_110812) do
16
+ create_table "stepper_motor_journeys", force: :cascade do |t|
17
+ t.string "type", null: false
18
+ t.string "state", default: "ready"
19
+ t.string "hero_type"
20
+ t.bigint "hero_id"
21
+ t.boolean "allow_multiple", default: false
22
+ t.string "previous_step_name"
23
+ t.string "next_step_name"
24
+ t.datetime "next_step_to_be_performed_at"
25
+ t.bigint "steps_entered", default: 0, null: false
26
+ t.bigint "steps_completed", default: 0, null: false
27
+ t.datetime "created_at", null: false
28
+ t.datetime "updated_at", null: false
29
+ t.string "idempotency_key"
30
+ t.index ["hero_type", "hero_id"], name: "index_stepper_motor_journeys_on_hero_type_and_hero_id"
31
+ t.index ["type", "hero_id", "hero_type"], name: "idx_journeys_one_per_hero_with_paused", unique: true, where: "allow_multiple = '0' AND state IN ('ready', 'performing', 'paused') /*application='Dummy'*/"
32
+ t.index ["type", "hero_type", "hero_id"], name: "index_stepper_motor_journeys_on_type_and_hero_type_and_hero_id"
33
+ t.index ["type"], name: "index_stepper_motor_journeys_on_type"
34
+ t.index ["updated_at"], name: "index_stepper_motor_journeys_on_updated_at", where: "state = 'canceled' OR state = 'finished' /*application='Dummy'*/"
35
+ t.index ["updated_at"], name: "stuck_journeys_index", where: "state = 'performing' /*application='Dummy'*/"
36
+ end
37
+ end