Skip to content

Commit 16beb97

Browse files
authored
Make admin server port configurable (#130)
PR to solve #129 Now you can specify the `admin_port` field under `runtimeConfig` in the dbos-config.yaml file. Added a test to make sure we can specify a different port.
1 parent c32cad1 commit 16beb97

File tree

5 files changed

+46
-1
lines changed

5 files changed

+46
-1
lines changed

dbos/dbos-config.schema.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,10 @@
140140
"start": {
141141
"type": "array",
142142
"description": "Specify commands to run to start your application (Python only)"
143+
},
144+
"admin_port": {
145+
"type": "number",
146+
"description": "The port number of the admin server (Default: 3001)"
143147
}
144148
}
145149
},

dbos/dbos.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,10 @@ def _launch(self) -> None:
348348
self._executor_field = ThreadPoolExecutor(max_workers=64)
349349
self._sys_db_field = SystemDatabase(self.config)
350350
self._app_db_field = ApplicationDatabase(self.config)
351-
self._admin_server_field = AdminServer(dbos=self)
351+
admin_port = self.config["runtimeConfig"].get("admin_port")
352+
if admin_port is None:
353+
admin_port = 3001
354+
self._admin_server_field = AdminServer(dbos=self, port=admin_port)
352355

353356
if not os.environ.get("DBOS__VMID"):
354357
workflow_ids = self._sys_db.get_pending_workflows("local")

dbos/dbos_config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
class RuntimeConfig(TypedDict, total=False):
1616
start: List[str]
17+
admin_port: Optional[int]
1718

1819

1920
class DatabaseConfig(TypedDict, total=False):

tests/test_admin_server.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,39 @@ def test_step(var2: str) -> str:
123123
time.sleep(1)
124124
print(f"Attempt {attempt + 1} failed. Retrying in 1 second...")
125125
assert succeeded, "Workflow did not recover"
126+
127+
128+
def test_admin_diff_port(cleanup_test_databases: None) -> None:
129+
# Initialize singleton
130+
DBOS.destroy() # In case of other tests leaving it
131+
132+
config_string = """name: test-app
133+
language: python
134+
database:
135+
hostname: localhost
136+
port: 5432
137+
username: postgres
138+
password: ${PGPASSWORD}
139+
app_db_name: dbostestpy
140+
runtimeConfig:
141+
start:
142+
- python3 main.py
143+
admin_port: 8001
144+
"""
145+
# Write the config to a text file for the moment
146+
with open("dbos-config.yaml", "w") as file:
147+
file.write(config_string)
148+
149+
try:
150+
# Initialize DBOS
151+
DBOS()
152+
DBOS.launch()
153+
154+
# Test GET /dbos-healthz
155+
response = requests.get("http://localhost:8001/dbos-healthz", timeout=5)
156+
assert response.status_code == 200
157+
assert response.text == "healthy"
158+
finally:
159+
# Clean up after the test
160+
DBOS.destroy()
161+
os.remove("dbos-config.yaml")

tests/test_config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ def test_valid_config(mocker):
3232
runtimeConfig:
3333
start:
3434
- "python3 main.py"
35+
admin_port: 8001
3536
database:
3637
hostname: 'some host'
3738
port: 1234

0 commit comments

Comments
 (0)