From 49af48cb8c2df250fb959096e898a5e5ebd738bc Mon Sep 17 00:00:00 2001 From: Michael van Rooijen Date: Wed, 13 Mar 2024 11:33:25 +0100 Subject: [PATCH] Add support for dashes in `HireFire::Worker` names --- CHANGELOG.md | 4 ++++ lib/hirefire/worker.rb | 2 +- test/hirefire/test_worker.rb | 36 +++++++++++++++++++++++++++++++----- 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c7f8d0..d4d6c6d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## HEAD + +* Add support for dashes in `HireFire::Worker` names to match the Procfile process naming format. `HireFire::Worker` is implicitly used when configuring HireFire using the `HireFire::Configuration#dyno` method. + ## v1.0.1 * Fix issue where jobs that were enqueued using `sidekiq < 7.2.1` and then processed with `sidekiq >= 7.2.1` (after updating) resulted in a `NoMethodError: undefined method 'queue' for Hash` error during checkups. diff --git a/lib/hirefire/worker.rb b/lib/hirefire/worker.rb index 51d558c..d909642 100644 --- a/lib/hirefire/worker.rb +++ b/lib/hirefire/worker.rb @@ -6,7 +6,7 @@ class InvalidDynoNameError < StandardError; end class MissingDynoBlockError < StandardError; end - PROCESS_NAME_PATTERN = /\A[a-zA-Z][a-zA-Z0-9_]{0,29}\z/ + PROCESS_NAME_PATTERN = /\A[a-zA-Z][a-zA-Z0-9_-]{0,29}\z/ attr_reader :name diff --git a/test/hirefire/test_worker.rb b/test/hirefire/test_worker.rb index aaf6281..d1a323e 100644 --- a/test/hirefire/test_worker.rb +++ b/test/hirefire/test_worker.rb @@ -4,14 +4,40 @@ class HireFire::WorkerTest < Minitest::Test def test_setup_and_methods - worker = HireFire::Worker.new(:worker) { 1 + 1 } - assert_equal :worker, worker.name - assert_equal 2, worker.value + valid_names = [ + "worker", + "worker1", + "my-worker", + "my_worker", + "Worker_123", + "worker-123", + "w", + "a" * 30 + ] + + valid_names.each do |name| + worker = HireFire::Worker.new(name) { 1 + 1 } + assert_equal name, worker.name + assert_equal 2, worker.value + end end def test_invalid_dyno_name_error - assert_raises(HireFire::Worker::InvalidDynoNameError) do - HireFire::Worker.new("invalid name") { 1 + 1 } + invalid_names = [ + "", # Empty string + "1worker", # Starts with a digit + "-worker", # Starts with a dash + "_worker", # Starts with an underscore + "worker!", # Contains an invalid character + " worker", # Starts with a space + "worker ", # Ends with a space + "a" * 31 # Exceeds maximum length + ] + + invalid_names.each do |name| + assert_raises(HireFire::Worker::InvalidDynoNameError) do + HireFire::Worker.new(name) { 1 + 1 } + end end end