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

Add Ability to overwrite task settings when calling a task in Functional API #717

Closed
cicdw opened this issue Mar 11, 2019 · 5 comments
Closed
Assignees

Comments

@cicdw
Copy link
Member

cicdw commented Mar 11, 2019

Currently, a common pattern is:

t = MyTask(name="test task", tags=["A"])

with Flow() as f:
   res1 = t(1)
   res2 = t(2)
   ...

and each individual copied instance of the task will appear with the same name "test task" in the UI and any other place that information is surfaced.

To allow for more nuanced control of the copying of tasks, we should add a reserved kwarg _task_args to task call signatures which allow for overriding things (such as name) when calling / copying the task.

@cicdw
Copy link
Member Author

cicdw commented Mar 14, 2019

Just throwing this out there, but another option would be some sugar like:

t = MyTask(name="test task", tags=["A"])

with Flow() as f:
   res1 = t["one"](1)
   res2 = t["two"](2)

which could be used to rename the individual tasks "test task[one]" and "test task[two]".

This would mean the current __getitem__ implementation would be gone, but I personally don't see people using tasks which are so small that they are going to be using / expecting that behavior.

The reason I'm suggesting this different idea is that I think the documentation for the special kwargs to task.__call__ are somewhat hidden (they don't naturally appear in a docstring for example), so I'm hesitant to pile on more things there.

@jlowin
Copy link
Member

jlowin commented Mar 17, 2019

This __getitem__ sugar feels very unnatural to me; it doesn't have any Python analogue. (The existing getitem sugar is tenuous, but at least it mimics Python behavior of indexing an object.)

Also, this would only solve the issue for names, not for other attributes like triggers.

If the issue is documentation, then we need to add more.

@cicdw
Copy link
Member Author

cicdw commented Mar 17, 2019

Also, this would only solve the issue for names, not for other attributes like triggers.

Right, but I suspect names will be the only thing people really use this for, which is why I was trying to brainstorm a leaner version than

new_task = old_task(a, b, c, y, _task_args={"name": "new_task"})

which feels clunky to me, and is attempting to solve a more general problem than the one we know about (names in the UI). For things like triggers, retries, etc. I think people will simply create new task instances because at that point the underlying task is probably fundamentally different anyway.

But, if we think a reserved kwarg is the way to go, then I suppose adding one layer of depth to the argument for the sake of supporting a more general pattern isn't so bad.

@jlowin
Copy link
Member

jlowin commented Mar 17, 2019

I think this feature is going to add a lot of utility to FunctionTasks (and the @task decorator more broadly) because it will allow those tasks to be reused without having to rewrite them. Currently, to use the same @task-decorated function as a task with two different retry behaviors, you have to rewrite the decorated function just to change the retry value. With this kwarg, you could affect the same behavior much more cleanly. I'd vote that this is a very explicit form of controlling behavior and should have a very explicit implementation.

@cicdw
Copy link
Member Author

cicdw commented Mar 17, 2019

Good point 👍🏻👍🏻

@jlowin jlowin added this to the Countdown to Open Source 🚀 milestone Mar 19, 2019
@cicdw cicdw self-assigned this Mar 19, 2019
@cicdw cicdw mentioned this issue Mar 19, 2019
zanieb pushed a commit that referenced this issue Jan 12, 2022
Implement api services and subscribe composition
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants