Skip to content

Commit f007614

Browse files
feat(executors): add config name and metadata support
1 parent 762d195 commit f007614

4 files changed

Lines changed: 32 additions & 2 deletions

File tree

libs/executors/garf/executors/config.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,32 @@
3030
from typing_extensions import Self
3131

3232

33+
class ConfigMetadata(pydantic.BaseModel):
34+
"""Contains optional metadata on config.
35+
36+
Attributes:
37+
description: Brief description of workflow.
38+
version: Version of workflow.
39+
"""
40+
41+
description: str | None = None
42+
version: str | None = None
43+
44+
3345
class Config(pydantic.BaseModel):
3446
"""Stores necessary parameters for one or multiple API sources.
3547
3648
Attributes:
3749
source: Mapping between API source alias and execution parameters.
50+
global_parameters: Common parameters for each source.
51+
name: Optional name of config.
52+
metadata: Optional metadata for config.
3853
"""
3954

4055
sources: dict[str, ExecutionContext]
4156
global_parameters: ExecutionContext | None = None
57+
name: str | None = None
58+
metadata: ConfigMetadata = ConfigMetadata()
4259

4360
@classmethod
4461
def from_file(cls, path: str | pathlib.Path | os.PathLike[str]) -> Config:

libs/executors/garf/executors/workflows/workflow.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,10 @@ class Workflow(pydantic.BaseModel):
178178
Attributes:
179179
steps: Contains one or several fetcher executions.
180180
context: Query and fetcher parameters to overwrite in steps.
181+
execution_config: Optional config for running workflow.
182+
prefix: Optional location of workflow.
183+
name: Optional name of workflow.
184+
metadata: Optional metadata.
181185
"""
182186

183187
steps: list[ExecutionStep]

libs/executors/garf/executors/workflows/workflow_runner.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ def run(
8383
workflow_attributes.update({'workflow.name': name})
8484
if version := self.workflow.metadata.version:
8585
workflow_attributes.update({'workflow.version': version})
86+
if config := self.workflow.execution_config:
87+
if config_version := config.metadata.version:
88+
workflow_attributes.update({'config.version': config_version})
89+
if config_name := config.name:
90+
workflow_attributes.update({'config.name': config_name})
8691
if workflow_attributes:
8792
span.set_attributes(workflow_attributes)
8893
self.workflow.compile()

libs/executors/tests/unit/test_config.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class TestConfig:
2020
def test_from_file_returns_correct_context_from_data(self, tmp_path):
2121
tmp_config = tmp_path / 'config.yaml'
2222
data = {
23+
'name': 'test_config',
2324
'sources': {
2425
'api': {
2526
'query_parameters': {
@@ -38,7 +39,8 @@ def test_from_file_returns_correct_context_from_data(self, tmp_path):
3839
'destination_folder': '/tmp',
3940
},
4041
}
41-
}
42+
},
43+
'metadata': {'version': '0.0.0'},
4244
}
4345
with open(tmp_config, 'w', encoding='utf-8') as f:
4446
yaml.dump(data, f, encoding='utf-8')
@@ -49,6 +51,7 @@ def test_from_file_returns_correct_context_from_data(self, tmp_path):
4951
def test_save_returns_correct_data(self, tmp_path):
5052
tmp_config = tmp_path / 'config.yaml'
5153
data = {
54+
'name': 'test_config',
5255
'sources': {
5356
'api': {
5457
'query_parameters': {
@@ -67,7 +70,8 @@ def test_save_returns_correct_data(self, tmp_path):
6770
'destination_folder': '/tmp',
6871
},
6972
}
70-
}
73+
},
74+
'metadata': {'version': '0.0.0'},
7175
}
7276
config = Config(**data)
7377
config.save(tmp_config)

0 commit comments

Comments
 (0)