You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Please describe how the feature works today
In #2443, @jcrist added a new conditional API to Prefect, which is 馃挴. However, at this moment, it can only be used with the functional API (as it requires a flow in the Prefect context).
Proposed behavior
Please describe your proposed change to the current behavior
The check for case in context currently takes place in Task.bind(), which is called by the functional API but not common imperative patterns like Task.set_upstream(), Task.set_downstream(), Task.set_dependencies(), Flow.add_task(), or Flow.set_dependencies().
I believe Flow.add_task() is the lowest-level API (called by all the others mentioned above) and consequently might be an opportune place to move the check for case in context. This way, adding a task to a flow while in a conditional block would automatically add it to the case class as well. Since the flow is (obviously) available when Flow.add_task() is called, it can be used inside the case context manager when calling bind() and set_upstream().
I think this would enable the following imperative syntax, while still using the existing case context managers:
Switch = Task()
A = Task()
B = Task()
C = Task()
f = Flow('imperative flow')
switch = Switch()
f.add_task(switch)
with case(switch, 'foo'):
f.add_task(A())
with case(switch, 'bar'):
b = B()
c = C()
c.set_upstream(b, flow=f)
Example
Please give an example of how the enhancement would be useful
The text was updated successfully, but these errors were encountered:
I was playing with that, but since Case.add_task() is always called from a parent method that has a flow object available, I think we can actually hide that from the user. For example, in the current implementation, it's called from Task.bind() which has a flow object in scope, so the signature could be Case.add_task(task: Task, flow: Flow=None). We might want to validate that all passed flows are the same for a given case context manager, but by passing it to add_task we can probably hide the need for users to pass it explicitly
Current behavior
Please describe how the feature works today
In #2443, @jcrist added a new conditional API to Prefect, which is 馃挴. However, at this moment, it can only be used with the functional API (as it requires a
flow
in the Prefect context).Proposed behavior
Please describe your proposed change to the current behavior
The check for
case
in context currently takes place inTask.bind()
, which is called by the functional API but not common imperative patterns likeTask.set_upstream()
,Task.set_downstream()
,Task.set_dependencies()
,Flow.add_task()
, orFlow.set_dependencies()
.I believe
Flow.add_task()
is the lowest-level API (called by all the others mentioned above) and consequently might be an opportune place to move the check forcase
in context. This way, adding a task to a flow while in a conditional block would automatically add it to thecase
class as well. Since the flow is (obviously) available whenFlow.add_task()
is called, it can be used inside thecase
context manager when callingbind()
andset_upstream()
.I think this would enable the following imperative syntax, while still using the existing case context managers:
Example
Please give an example of how the enhancement would be useful
The text was updated successfully, but these errors were encountered: