https://flyte.org logo
#ask-the-community
Title
# ask-the-community
b

Brandon Segal

07/21/2023, 5:10 PM
Is it possible to modify the FlyteContext in a way that allows us to add attributes to the ExecutionParamaters for example? The situation is that our flyte launch plans are executed from a separate cron system that has it's own execution_id that we want to reference in our tasks for things like tagging infrastructure that is instantiated during the task. The reason for not just adding the cron execution_id to the inputs is that we also want to take advantage of caching and if the execution id is passed as part of the input parameters then the task outputs will always be associated with that single execution. Alternatively it would be amazing to be able to configure how the input is hashed so that only certain input parameters are considered for the key to the cache.
k

Kevin Su

07/21/2023, 5:29 PM
yes, you are able to add attributes to ExecutionParamaters. here is an example. https://github.com/flyteorg/flytekit/pull/1725/files#diff-b7d319a6a758a21cb9e78fe6c150fdbf4f5ec7173a0468253655601bbf86aeb3R49
Copy code
ctx.user_space_params._attrs["GET_ORIGINAL_TASK"] = True
b

Brandon Segal

07/21/2023, 5:37 PM
And would this user_space_param be persisted across the other tasks if I did this modification in the beginning? I'm thinking something like :
Copy code
@task
def task_1(execution_id:str):
  ctx = FlyteContextManager.get_current_context()
  ctx.user_space_params._attrs["GET_ORIGINAL_TASK"] = True

@task
def task_2():
  ctx = FlyteContextManager.get_current_context()
  print(ctx.user_space_params._attrs["GET_ORIGINAL_TASK"]) 

@workflow()
def wf(execution_id:str)->None:
  task_1_output = task_1()
  task_2_output = task_2()
  task_1_output >> task_2_output
k

Kevin Su

07/21/2023, 5:40 PM
ahh, flytekit context can’t be shared across the tasks. how about passing an env to the workflow?
b

Brandon Segal

07/21/2023, 5:41 PM
Oh you can pass in an environment to the workflow?
k

Kevin Su

07/21/2023, 5:50 PM
yes, you can. you add it through
pyflyte run --env
UI is not supported yet
b

Brandon Segal

07/21/2023, 5:55 PM
Ah so when the launchplan is executed by our system we could run it while passing in the environment variables.
k

Ketan (kumare3)

07/21/2023, 6:42 PM
ya also, launchplan can have default env vars set
5 Views