Skip to content

Commit

Permalink
Add support for dashes in Worker names
Browse files Browse the repository at this point in the history
  • Loading branch information
mrrooijen committed Mar 12, 2024
1 parent 4215861 commit 06a04a4
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 9 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
No changes since release yet.
## HEAD

* Add support for dashes in `Worker` names to match the Procfile process naming format. `Worker` is implicitly used when configuring HireFire using the `Configuration#dyno` method.

## v1.0.0

* Initial release.
2 changes: 1 addition & 1 deletion hirefire_resource/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class MissingDynoProcError(Exception):


class Worker:
PROCESS_NAME_PATTERN = r"^[a-zA-Z][a-zA-Z0-9_]{0,29}$"
PROCESS_NAME_PATTERN = r"^[a-zA-Z][a-zA-Z0-9_-]{0,29}$"

def __init__(self, name, proc=None):
self._validate(name, proc)
Expand Down
38 changes: 31 additions & 7 deletions tests/hirefire_resource/test_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,39 @@
from hirefire_resource.worker import InvalidDynoNameError, MissingDynoProcError, Worker


def test_worker_initialization_and_methods():
worker = Worker("worker", lambda: 1.23)
assert worker.name == "worker"
assert worker.value() == 1.23
def test_worker_valid_initialization():
valid_names = [
"worker",
"worker1",
"my-worker",
"my_worker",
"Worker_123",
"worker-123",
"w",
"a" * 30,
]

for name in valid_names:
worker = Worker(name, lambda: 1.23)
assert worker.name == name
assert worker.value() == 1.23

def test_invalid_dyno_name_error():
with pytest.raises(InvalidDynoNameError):
Worker("invalid name", lambda: 1.23)

def test_worker_invalid_name_raises_error():
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
]

for name in invalid_names:
with pytest.raises(InvalidDynoNameError):
Worker(name, lambda: 1.23)


def test_missing_dyno_proc_error():
Expand Down

0 comments on commit 06a04a4

Please sign in to comment.