Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow optional explicit naming of workflow and activity names #623

Closed
bkcsfi opened this issue Oct 26, 2023 · 1 comment · Fixed by #651
Closed

allow optional explicit naming of workflow and activity names #623

bkcsfi opened this issue Oct 26, 2023 · 1 comment · Fixed by #651
Labels

Comments

@bkcsfi
Copy link

bkcsfi commented Oct 26, 2023

Describe the proposal

It would be helpful to allow users to explicitly declare the name of an activity or workflow when they are registered, and the name of a called activity, as an alternative to using the activity or workflow function __name__.

Consider an application that can download and process files from various sources, A, B and C. In the future, additional sources will be added.

Here's one way to lay out the code.

/src
  /interface
     /A
        /activities.py
     /B
        /activities.py
     /C
        /activities.py
     /D
        /activities.py

Suppose each source has the same nominal activity get_input_file

I think it would be cleaner to use these activities this way:

from interface import A, B, C, D
...
input_module = A if input_type == 'A' else B
file_result = yield ctx.call_activity(input_module.get_input_file)
...

Currently the activity name will be taken from the function name, there's no way to have the same activity in different modules.

Therefore I have to write code like this instead:

from interface import A, B, C, D
...
if input_type == 'A':
    file_result = yield ctx.call_activity(A.get_input_file_A)
else:
    file_result = yield ctx.call_activity(B.get_input_file_B)
...

If an optional name can be explicitly passed to call_activity, register_activity and register_workflow, then users could manage complicated workflows in a tidier way.

for example, I would write a decorator to assign an __registered_name attribute to my activity functions.

Then I would use a wrapper function to call activities, something like:

def call_activity(ctx, activity, *arg):
   yield ctx.call_activity(activity.__registered_name, *arg)

...

from interface import A, B, C, D
...
input_module = A if input_type == 'A' else B
file_result = yield call_activity(ctx,input_module.get_input_file)
...
@mukundansundar
Copy link
Contributor

mukundansundar commented Dec 13, 2023

PR #651 addresses this issue.

@berndverst berndverst added this to the v1.13 milestone Jan 24, 2024
@berndverst berndverst modified the milestones: v1.13, workflow-0.4.0 Feb 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants