Skip to content

Commit 51bd22b

Browse files
authored
Application Version and Executor ID in DBOSConfig (#417)
Addresses #411
1 parent 1c3874a commit 51bd22b

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

dbos/_dbos.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,17 @@ def __init__(
324324
self.conductor_websocket: Optional[ConductorWebsocket] = None
325325
self._background_event_loop: BackgroundEventLoop = BackgroundEventLoop()
326326

327+
# Globally set the application version and executor ID.
328+
# In DBOS Cloud, instead use the values supplied through environment variables.
329+
if not os.environ.get("DBOS__CLOUD") == "true":
330+
if (
331+
"application_version" in config
332+
and config["application_version"] is not None
333+
):
334+
GlobalParams.app_version = config["application_version"]
335+
if "executor_id" in config and config["executor_id"] is not None:
336+
GlobalParams.executor_id = config["executor_id"]
337+
327338
init_logger()
328339

329340
# Translate user provided config to an internal format

dbos/_dbos_config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ class DBOSConfig(TypedDict, total=False):
4747
admin_port: Optional[int]
4848
run_admin_server: Optional[bool]
4949
otlp_attributes: Optional[dict[str, str]]
50+
application_version: Optional[str]
51+
executor_id: Optional[str]
5052

5153

5254
class RuntimeConfig(TypedDict, total=False):

tests/test_dbos.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1397,7 +1397,7 @@ def workflow_one(x: int) -> int:
13971397
assert GlobalParams.app_version != app_version
13981398

13991399
# Verify that version can be overriden with an environment variable
1400-
app_version = "12345"
1400+
app_version = str(uuid.uuid4())
14011401
os.environ["DBOS__APPVERSION"] = app_version
14021402

14031403
DBOS.destroy(destroy_registry=True)
@@ -1412,6 +1412,28 @@ def workflow_one(x: int) -> int:
14121412

14131413
del os.environ["DBOS__APPVERSION"]
14141414

1415+
# Verify that version and executor ID can be overriden with a config parameter
1416+
app_version = str(uuid.uuid4())
1417+
executor_id = str(uuid.uuid4())
1418+
1419+
DBOS.destroy(destroy_registry=True)
1420+
config["application_version"] = app_version
1421+
config["executor_id"] = executor_id
1422+
DBOS(config=config)
1423+
1424+
@DBOS.workflow()
1425+
def test_workflow() -> str:
1426+
assert DBOS.workflow_id
1427+
return DBOS.workflow_id
1428+
1429+
DBOS.launch()
1430+
assert GlobalParams.app_version == app_version
1431+
assert GlobalParams.executor_id == executor_id
1432+
wfid = test_workflow()
1433+
handle: WorkflowHandle[str] = DBOS.retrieve_workflow(wfid)
1434+
assert handle.get_status().app_version == app_version
1435+
assert handle.get_status().executor_id == executor_id
1436+
14151437

14161438
def test_recovery_appversion(config: DBOSConfig) -> None:
14171439
input = 5

0 commit comments

Comments
 (0)