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

Commit

Permalink
user actions: convert constants to text choices
Browse files Browse the repository at this point in the history
  • Loading branch information
DonHaul committed Jul 30, 2024
1 parent e45de6c commit a243824
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 17 deletions.
2 changes: 1 addition & 1 deletion backoffice/backoffice/workflows/airflow_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def restart_workflow_dags(workflow_id, workflow_type, params=None):
delete_workflow_dag(dag_id, workflow_id)

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

return JsonResponse(
Expand Down
6 changes: 4 additions & 2 deletions backoffice/backoffice/workflows/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,13 @@ def create(self, request):
)
logger.info(
"Trigger Airflow DAG: %s for %s",
WORKFLOW_DAGS[workflow.workflow_type][0],
WORKFLOW_DAGS[workflow.workflow_type].initialize,
workflow.id,
)
return airflow_utils.trigger_airflow_dag(
WORKFLOW_DAGS[workflow.workflow_type][0], str(workflow.id), workflow.data
WORKFLOW_DAGS[workflow.workflow_type].initialize,
str(workflow.id),
workflow.data,
)

@action(detail=True, methods=["post"])
Expand Down
18 changes: 12 additions & 6 deletions backoffice/backoffice/workflows/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,19 @@ class ResolutionDags(models.TextChoices):
reject = "reject", "author_create_rejected_dag"


class AuthorCreateDags(models.TextChoices):
initialize = "author_create_initialization_dag", "initialize"
approve = "author_create_approved_dag", "approve"
reject = "author_create_rejected_dag", "reject"


class AuthorUpdateDags(models.TextChoices):
initialize = "author_update_dag", "initialize"


WORKFLOW_DAGS = {
WorkflowType.HEP_CREATE: "",
WorkflowType.HEP_UPDATE: "",
WorkflowType.AUTHOR_CREATE: (
"author_create_initialization_dag",
"author_create_approved_dag",
"author_create_rejected_dag",
),
WorkflowType.AUTHOR_UPDATE: ("author_update_dag",),
WorkflowType.AUTHOR_CREATE: AuthorCreateDags,
WorkflowType.AUTHOR_UPDATE: AuthorUpdateDags,
}
5 changes: 1 addition & 4 deletions backoffice/backoffice/workflows/tests/test_airflow_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import time
import uuid

import pytest
Expand All @@ -15,7 +14,7 @@ class TestAirflowUtils(TransactionTestCase):
def setUp(self):
self.workflow_id = uuid.UUID(int=1)
self.workflow_type = WorkflowType.AUTHOR_CREATE
self.dag_id = WORKFLOW_DAGS[self.workflow_type][0]
self.dag_id = WORKFLOW_DAGS[self.workflow_type].initialize
self.response = airflow_utils.trigger_airflow_dag(
self.dag_id, str(self.workflow_id)
)
Expand All @@ -29,7 +28,6 @@ def test_trigger_airflow_dag(self):

@pytest.mark.vcr()
def test_restart_failed_tasks(self):
time.sleep(20) # wait for dag to fail
response = airflow_utils.restart_failed_tasks(
self.workflow_id, self.workflow_type
)
Expand All @@ -45,7 +43,6 @@ def test_find_executed_dags(self):

@pytest.mark.vcr()
def test_find_failed_dag(self):
time.sleep(20) # wait for dag to fail
failed_dag = airflow_utils.find_failed_dag(self.workflow_id, self.workflow_type)
self.assertEqual(self.dag_id, failed_dag)

Expand Down
8 changes: 4 additions & 4 deletions backoffice/backoffice/workflows/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,15 +261,15 @@ def setUp(self):
id=uuid.UUID(int=0),
)
airflow_utils.trigger_airflow_dag(
WORKFLOW_DAGS[self.workflow.workflow_type][0],
WORKFLOW_DAGS[self.workflow.workflow_type].initialize,
str(self.workflow.id),
self.workflow.data,
)

def tearDown(self):
super().tearDown()
airflow_utils.delete_workflow_dag(
WORKFLOW_DAGS[self.workflow.workflow_type][0], str(self.workflow.id)
WORKFLOW_DAGS[self.workflow.workflow_type].initialize, str(self.workflow.id)
)

@pytest.mark.vcr()
Expand Down Expand Up @@ -309,7 +309,7 @@ def test_accept_author(self):
self.assertEqual(response.status_code, 200)

airflow_utils.delete_workflow_dag(
WORKFLOW_DAGS["AUTHOR_CREATE"][1], str(self.workflow.id)
WORKFLOW_DAGS["AUTHOR_CREATE"].approve, str(self.workflow.id)
)

@pytest.mark.vcr()
Expand All @@ -328,7 +328,7 @@ def test_reject_author(self):
self.assertEqual(response.status_code, 200)

airflow_utils.delete_workflow_dag(
WORKFLOW_DAGS["AUTHOR_CREATE"][2], str(self.workflow.id)
WORKFLOW_DAGS["AUTHOR_CREATE"].reject, str(self.workflow.id)
)

@pytest.mark.vcr()
Expand Down

0 comments on commit a243824

Please sign in to comment.