Skip to content

Commit

Permalink
Add support for dashes in HireFire::Worker names
Browse files Browse the repository at this point in the history
  • Loading branch information
mrrooijen committed Mar 13, 2024
1 parent 2d0180e commit 49af48c
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion lib/hirefire/worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
36 changes: 31 additions & 5 deletions test/hirefire/test_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 49af48c

Please sign in to comment.