Doubt regarding use case of UserConfig class in director/settings.py
Closed this issue · 2 comments
I saw the UserConfig
class defined in director/settings.py
file. What is the real use of this class?
It is instantiated in director/ _init_.py file but I didn't saw any use for it.
Hello,
The purpose is to expose the config to your tasks in your own workflows.
Let's suppose you have this setup (I basically just ran director init .
at this time):
$ tree -a
.
├── .env
├── tasks
│ └── etl.py
└── workflows.yml
1 directory, 3 files
Now you want to add some config option for your tasks such as: MY_CUSTOM_DATA="Hello, world!"
.
You would add this option to your .env file like this:
$ echo 'DIRECTOR_MY_CUSTOM_DATA="Hello, world!"' >>.env
(Note the DIRECTOR_
prefix which is required for your option to be exposed)
Then in tasks/etl.py you can access it with:
from director import config, task
@task(name="EXTRACT")
def extract(*args, **kwargs):
print(f"Extracting data: {config['MY_CUSTOM_DATA']}")
(Note that you don't need the DIRECTOR_
prefix to access the option)
But you are right that this should probably be documented at some point.
Yes, Documenting this would be great.