Skip to content
This repository has been archived by the owner on Nov 21, 2024. It is now read-only.

Commit

Permalink
backoffice: fix restart with params
Browse files Browse the repository at this point in the history
  • Loading branch information
DonHaul committed Aug 27, 2024
1 parent d52647a commit 8157b87
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 57 deletions.
10 changes: 8 additions & 2 deletions backoffice/backoffice/workflows/airflow_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,23 +156,29 @@ def restart_workflow_dags(workflow_id, workflow_type, params=None):
:param params: parameters of new dag execution
:returns: request response
"""

delete_workflow_dag_runs(workflow_id, workflow_type)

return trigger_airflow_dag(
WORKFLOW_DAGS[workflow_type].initialize, str(workflow_id), params
)


def delete_workflow_dag_runs(workflow_id, workflow_type):
def delete_workflow_dag_runs(workflow_id, workflow_type, params=None):
"""Deletes runs of a given workflow.
:param workflow_id: workflow_id for dags that should be restarted
:param workflow_type: type of workflow the will be restarted
"""
executed_dags_for_workflow = find_executed_dags(workflow_id, workflow_type)

for dag_id in executed_dags_for_workflow:
data = None

for dag_id, dag_data in executed_dags_for_workflow.items():
delete_workflow_dag(dag_id, str(workflow_id))
# fetch data from previous drag run
if data is None:
data = dag_data["conf"].get("data")

return JsonResponse(
data={"message": f"Dag runs for worfklow {workflow_id} have been deleted"}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
interactions:
- request:
body: '{"dag_run_id": "00000000-0000-0000-0000-000000000000", "conf": {"workflow_id":
"00000000-0000-0000-0000-000000000000"}}'
"00000000-0000-0000-0000-000000000000", "data": {"test": "test"}}}'
headers:
Accept:
- '*/*'
Expand All @@ -10,30 +10,33 @@ interactions:
Connection:
- keep-alive
Content-Length:
- '119'
- '145'
Content-Type:
- application/json
method: POST
uri: http://airflow-webserver:8080/api/v1/dags/author_create_initialization_dag/dagRuns
response:
body:
string: "{\n \"conf\": {\n \"workflow_id\": \"00000000-0000-0000-0000-000000000000\"\n
\ },\n \"dag_id\": \"author_create_initialization_dag\",\n \"dag_run_id\":
\"00000000-0000-0000-0000-000000000000\",\n \"data_interval_end\": \"2024-07-30T12:14:28.743346+00:00\",\n
\ \"data_interval_start\": \"2024-07-30T12:14:28.743346+00:00\",\n \"end_date\":
null,\n \"execution_date\": \"2024-07-30T12:14:28.743346+00:00\",\n \"external_trigger\":
true,\n \"last_scheduling_decision\": null,\n \"logical_date\": \"2024-07-30T12:14:28.743346+00:00\",\n
\ \"note\": null,\n \"run_type\": \"manual\",\n \"start_date\": null,\n
\ \"state\": \"queued\"\n}\n"
string: "{\n \"conf\": {\n \"data\": {\n \"test\": \"test\"\n },\n
\ \"workflow_id\": \"00000000-0000-0000-0000-000000000000\"\n },\n \"dag_id\":
\"author_create_initialization_dag\",\n \"dag_run_id\": \"00000000-0000-0000-0000-000000000000\",\n
\ \"data_interval_end\": \"2024-08-21T13:20:42.301248+00:00\",\n \"data_interval_start\":
\"2024-08-21T13:20:42.301248+00:00\",\n \"end_date\": null,\n \"execution_date\":
\"2024-08-21T13:20:42.301248+00:00\",\n \"external_trigger\": true,\n \"last_scheduling_decision\":
null,\n \"logical_date\": \"2024-08-21T13:20:42.301248+00:00\",\n \"note\":
null,\n \"run_type\": \"manual\",\n \"start_date\": null,\n \"state\":
\"queued\"\n}\n"
headers:
Cache-Control:
- no-store
Connection:
- close
Content-Length:
- '579'
- '621'
Content-Type:
- application/json
Date:
- Tue, 30 Jul 2024 12:14:28 GMT
- Wed, 21 Aug 2024 13:20:42 GMT
Server:
- gunicorn
X-Robots-Tag:
Expand All @@ -50,29 +53,30 @@ interactions:
- gzip, deflate
Connection:
- keep-alive
Content-Type:
- application/json
method: GET
uri: http://airflow-webserver:8080/api/v1/dags/author_create_initialization_dag/dagRuns/00000000-0000-0000-0000-000000000000
response:
body:
string: "{\n \"conf\": {\n \"workflow_id\": \"00000000-0000-0000-0000-000000000000\"\n
\ },\n \"dag_id\": \"author_create_initialization_dag\",\n \"dag_run_id\":
\"00000000-0000-0000-0000-000000000000\",\n \"data_interval_end\": \"2024-07-30T12:14:28.743346+00:00\",\n
\ \"data_interval_start\": \"2024-07-30T12:14:28.743346+00:00\",\n \"end_date\":
null,\n \"execution_date\": \"2024-07-30T12:14:28.743346+00:00\",\n \"external_trigger\":
true,\n \"last_scheduling_decision\": null,\n \"logical_date\": \"2024-07-30T12:14:28.743346+00:00\",\n
\ \"note\": null,\n \"run_type\": \"manual\",\n \"start_date\": null,\n
\ \"state\": \"queued\"\n}\n"
string: "{\n \"conf\": {\n \"data\": {\n \"test\": \"test\"\n },\n
\ \"workflow_id\": \"00000000-0000-0000-0000-000000000000\"\n },\n \"dag_id\":
\"author_create_initialization_dag\",\n \"dag_run_id\": \"00000000-0000-0000-0000-000000000000\",\n
\ \"data_interval_end\": \"2024-08-21T13:20:42.301248+00:00\",\n \"data_interval_start\":
\"2024-08-21T13:20:42.301248+00:00\",\n \"end_date\": null,\n \"execution_date\":
\"2024-08-21T13:20:42.301248+00:00\",\n \"external_trigger\": true,\n \"last_scheduling_decision\":
null,\n \"logical_date\": \"2024-08-21T13:20:42.301248+00:00\",\n \"note\":
null,\n \"run_type\": \"manual\",\n \"start_date\": null,\n \"state\":
\"queued\"\n}\n"
headers:
Cache-Control:
- no-store
Connection:
- close
Content-Length:
- '579'
- '621'
Content-Type:
- application/json
Date:
- Tue, 30 Jul 2024 12:14:28 GMT
- Wed, 21 Aug 2024 13:20:42 GMT
Server:
- gunicorn
X-Robots-Tag:
Expand All @@ -89,24 +93,24 @@ interactions:
- gzip, deflate
Connection:
- keep-alive
Content-Type:
- application/json
method: GET
uri: http://airflow-webserver:8080/api/v1/dags/author_create_approved_dag/dagRuns/00000000-0000-0000-0000-000000000000
response:
body:
string: "{\n \"detail\": \"DAGRun with DAG ID: 'author_create_approved_dag'
and DagRun ID: '00000000-0000-0000-0000-000000000000' not found\",\n \"status\":
404,\n \"title\": \"DAGRun not found\",\n \"type\": \"https://airflow.apache.org/docs/apache-airflow/2.8.3/stable-rest-api-ref.html#section/Errors/NotFound\"\n}\n"
404,\n \"title\": \"DAGRun not found\",\n \"type\": \"https://airflow.apache.org/docs/apache-airflow/2.9.3/stable-rest-api-ref.html#section/Errors/NotFound\"\n}\n"
headers:
Cache-Control:
- no-store
Connection:
- close
Content-Length:
- '294'
Content-Type:
- application/problem+json
Date:
- Tue, 30 Jul 2024 12:14:28 GMT
- Wed, 21 Aug 2024 13:20:42 GMT
Server:
- gunicorn
X-Robots-Tag:
Expand All @@ -123,24 +127,24 @@ interactions:
- gzip, deflate
Connection:
- keep-alive
Content-Type:
- application/json
method: GET
uri: http://airflow-webserver:8080/api/v1/dags/author_create_rejected_dag/dagRuns/00000000-0000-0000-0000-000000000000
response:
body:
string: "{\n \"detail\": \"DAGRun with DAG ID: 'author_create_rejected_dag'
and DagRun ID: '00000000-0000-0000-0000-000000000000' not found\",\n \"status\":
404,\n \"title\": \"DAGRun not found\",\n \"type\": \"https://airflow.apache.org/docs/apache-airflow/2.8.3/stable-rest-api-ref.html#section/Errors/NotFound\"\n}\n"
404,\n \"title\": \"DAGRun not found\",\n \"type\": \"https://airflow.apache.org/docs/apache-airflow/2.9.3/stable-rest-api-ref.html#section/Errors/NotFound\"\n}\n"
headers:
Cache-Control:
- no-store
Connection:
- close
Content-Length:
- '294'
Content-Type:
- application/problem+json
Date:
- Tue, 30 Jul 2024 12:14:28 GMT
- Wed, 21 Aug 2024 13:20:42 GMT
Server:
- gunicorn
X-Robots-Tag:
Expand All @@ -159,20 +163,20 @@ interactions:
- keep-alive
Content-Length:
- '0'
Content-Type:
- application/json
method: DELETE
uri: http://airflow-webserver:8080/api/v1/dags/author_create_initialization_dag/dagRuns/00000000-0000-0000-0000-000000000000
response:
body:
string: ''
headers:
Cache-Control:
- no-store
Connection:
- close
Content-Type:
- application/json
Date:
- Tue, 30 Jul 2024 12:14:28 GMT
- Wed, 21 Aug 2024 13:20:49 GMT
Server:
- gunicorn
X-Robots-Tag:
Expand All @@ -182,7 +186,7 @@ interactions:
message: NO CONTENT
- request:
body: '{"dag_run_id": "00000000-0000-0000-0000-000000000000", "conf": {"workflow_id":
"00000000-0000-0000-0000-000000000000"}}'
"00000000-0000-0000-0000-000000000000", "data": {"test": "test"}}}'
headers:
Accept:
- '*/*'
Expand All @@ -191,30 +195,33 @@ interactions:
Connection:
- keep-alive
Content-Length:
- '119'
- '145'
Content-Type:
- application/json
method: POST
uri: http://airflow-webserver:8080/api/v1/dags/author_create_initialization_dag/dagRuns
response:
body:
string: "{\n \"conf\": {\n \"workflow_id\": \"00000000-0000-0000-0000-000000000000\"\n
\ },\n \"dag_id\": \"author_create_initialization_dag\",\n \"dag_run_id\":
\"00000000-0000-0000-0000-000000000000\",\n \"data_interval_end\": \"2024-07-30T12:14:29.037550+00:00\",\n
\ \"data_interval_start\": \"2024-07-30T12:14:29.037550+00:00\",\n \"end_date\":
null,\n \"execution_date\": \"2024-07-30T12:14:29.037550+00:00\",\n \"external_trigger\":
true,\n \"last_scheduling_decision\": null,\n \"logical_date\": \"2024-07-30T12:14:29.037550+00:00\",\n
\ \"note\": null,\n \"run_type\": \"manual\",\n \"start_date\": null,\n
\ \"state\": \"queued\"\n}\n"
string: "{\n \"conf\": {\n \"data\": {\n \"test\": \"test\"\n },\n
\ \"workflow_id\": \"00000000-0000-0000-0000-000000000000\"\n },\n \"dag_id\":
\"author_create_initialization_dag\",\n \"dag_run_id\": \"00000000-0000-0000-0000-000000000000\",\n
\ \"data_interval_end\": \"2024-08-21T13:20:49.946419+00:00\",\n \"data_interval_start\":
\"2024-08-21T13:20:49.946419+00:00\",\n \"end_date\": null,\n \"execution_date\":
\"2024-08-21T13:20:49.946419+00:00\",\n \"external_trigger\": true,\n \"last_scheduling_decision\":
null,\n \"logical_date\": \"2024-08-21T13:20:49.946419+00:00\",\n \"note\":
null,\n \"run_type\": \"manual\",\n \"start_date\": null,\n \"state\":
\"queued\"\n}\n"
headers:
Cache-Control:
- no-store
Connection:
- close
Content-Length:
- '579'
- '621'
Content-Type:
- application/json
Date:
- Tue, 30 Jul 2024 12:14:29 GMT
- Wed, 21 Aug 2024 13:20:49 GMT
Server:
- gunicorn
X-Robots-Tag:
Expand All @@ -233,20 +240,20 @@ interactions:
- keep-alive
Content-Length:
- '0'
Content-Type:
- application/json
method: DELETE
uri: http://airflow-webserver:8080/api/v1/dags/author_create_initialization_dag/dagRuns/00000000-0000-0000-0000-000000000000
response:
body:
string: ''
headers:
Cache-Control:
- no-store
Connection:
- close
Content-Type:
- application/json
Date:
- Tue, 30 Jul 2024 12:14:29 GMT
- Wed, 21 Aug 2024 13:20:56 GMT
Server:
- gunicorn
X-Robots-Tag:
Expand Down
10 changes: 5 additions & 5 deletions backoffice/backoffice/workflows/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ def setUp(self):
super().setUp()

self.workflow = Workflow.objects.create(
data={},
data={"test": "test"},
status="running",
core=True,
is_update=False,
Expand Down Expand Up @@ -419,8 +419,8 @@ def test_restart_full_dagrun(self):
kwargs={"pk": self.workflow.id},
)
response = self.api_client.post(url)

self.assertEqual(response.status_code, 200)
self.assertIn("test", response.json()["conf"]["data"])

@pytest.mark.vcr()
def test_restart_a_task(self):
Expand All @@ -429,8 +429,9 @@ def test_restart_a_task(self):
"api:workflows-authors-restart",
kwargs={"pk": self.workflow.id},
)

response = self.api_client.post(
url, json={"task_ids": ["set_workflow_status_to_running"]}
url, format="json", data={"restart_current_task": True}
)
self.assertEqual(response.status_code, 200)

Expand All @@ -441,9 +442,8 @@ def test_restart_with_params(self):
"api:workflows-authors-restart",
kwargs={"pk": self.workflow.id},
)

response = self.api_client.post(
url, json={"params": {"workflow_id": self.workflow.id}}
url, format="json", data={"params": {"workflow_id": self.workflow.id}}
)
self.assertEqual(response.status_code, 200)

Expand Down

0 comments on commit 8157b87

Please sign in to comment.