uranusjr commented on a change in pull request #19353:
URL: https://github.com/apache/airflow/pull/19353#discussion_r747256631
##########
File path: airflow/www/views.py
##########
@@ -3977,26 +3978,37 @@ class
DagRunModelView(AirflowPrivilegeVerifierModelView):
@action('muldelete', "Delete", "Are you sure you want to delete selected
records?", single=False)
@action_has_dag_edit_access
- @provide_session
- def action_muldelete(self, items, session=None):
+ def action_muldelete(self, items: List[DagRun]):
"""Multiple delete."""
self.datamodel.delete_all(items)
self.update_redirect()
return redirect(self.get_redirect())
+ @action('set_queued', "Set state to 'queued'", '', single=False)
+ @action_has_dag_edit_access
+ def action_set_queued(self, drs: List[DagRun]):
+ """Set state to queued."""
+ return self.set_dag_runs_to_active_state(drs, State.QUEUED)
+
@action('set_running', "Set state to 'running'", '', single=False)
@action_has_dag_edit_access
- @provide_session
- def action_set_running(self, drs, session=None):
+ def action_set_running(self, drs: List[DagRun]):
"""Set state to running."""
+ return self.set_dag_runs_to_active_state(drs, State.RUNNING)
+
+ @provide_session
+ def set_dag_runs_to_active_state(self, drs: List[DagRun], state: str,
session=None):
+ if state not in [State.RUNNING, State.QUEUED]:
+ raise ValueError("This routine only supports Running and Queued.")
try:
count = 0
for dr in session.query(DagRun).filter(DagRun.id.in_([dagrun.id
for dagrun in drs])).all():
Review comment:
Also why do we need to re-select the DagRun instances, if the input is
already a list of DagRun instances? Is this due to some weird SQLAlchemy or
Flask-Appbuilder quirk?
##########
File path: airflow/www/views.py
##########
@@ -3977,26 +3978,37 @@ class
DagRunModelView(AirflowPrivilegeVerifierModelView):
@action('muldelete', "Delete", "Are you sure you want to delete selected
records?", single=False)
@action_has_dag_edit_access
- @provide_session
- def action_muldelete(self, items, session=None):
+ def action_muldelete(self, items: List[DagRun]):
"""Multiple delete."""
self.datamodel.delete_all(items)
self.update_redirect()
return redirect(self.get_redirect())
+ @action('set_queued', "Set state to 'queued'", '', single=False)
+ @action_has_dag_edit_access
+ def action_set_queued(self, drs: List[DagRun]):
+ """Set state to queued."""
+ return self.set_dag_runs_to_active_state(drs, State.QUEUED)
+
@action('set_running', "Set state to 'running'", '', single=False)
@action_has_dag_edit_access
- @provide_session
- def action_set_running(self, drs, session=None):
+ def action_set_running(self, drs: List[DagRun]):
"""Set state to running."""
+ return self.set_dag_runs_to_active_state(drs, State.RUNNING)
+
+ @provide_session
+ def set_dag_runs_to_active_state(self, drs: List[DagRun], state: str,
session=None):
+ if state not in [State.RUNNING, State.QUEUED]:
+ raise ValueError("This routine only supports Running and Queued.")
try:
count = 0
for dr in session.query(DagRun).filter(DagRun.id.in_([dagrun.id
for dagrun in drs])).all():
Review comment:
```suggestion
for dr in session.query(DagRun).filter(DagRun.id.in_([dagrun.id
for dagrun in drs])):
```
Not related but let’s remove this unnecessary `all()` call.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]