diff --git a/workflows/__init__.py b/workflows/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/workflows/dags/author/author_create/author_create_approved.py b/workflows/dags/author/author_create/author_create_approved.py index 529fd4c0..083ae905 100644 --- a/workflows/dags/author/author_create/author_create_approved.py +++ b/workflows/dags/author/author_create/author_create_approved.py @@ -4,7 +4,6 @@ from airflow.decorators import dag, task from airflow.models.param import Param from airflow.utils.trigger_rule import TriggerRule -from author.author_create.shared_tasks import create_decision_on_curation_choice from hooks.backoffice.workflow_management_hook import AUTHORS, WorkflowManagementHook from hooks.backoffice.workflow_ticket_management_hook import ( WorkflowTicketManagementHook, @@ -25,6 +24,7 @@ params={ "workflow_id": Param(type="string", default=""), "data": Param(type="object", default={}), + "create_ticket": Param(type="boolean", default=False), }, start_date=datetime.datetime(2024, 5, 5), schedule=None, @@ -66,9 +66,10 @@ def author_check_approval_branch(**context: dict) -> None: dag goes either to create_ticket_on_author_approval task or directly to create_author_on_inspire """ - if context["params"]["data"]["create_ticket"]: + if context["params"]["create_ticket"]: return "create_author_create_curation_ticket" - return "close_author_create_user_ticket" + else: + return "empty_task" @task def create_author_create_curation_ticket(**context: dict) -> None: @@ -137,6 +138,11 @@ def set_author_create_workflow_status_to_completed(**context: dict) -> None: collection=AUTHORS, ) + @task + def empty_task() -> None: + # Logic to combine the results of branches + pass + @task() def set_author_create_workflow_status_to_error(**context: dict) -> None: ti = context["ti"] @@ -159,9 +165,24 @@ def set_author_create_workflow_status_to_error(**context: dict) -> None: set_author_create_workflow_status_to_completed() ) set_workflow_status_to_error_task = set_author_create_workflow_status_to_error() - create_decision_on_curation_choice_task = create_decision_on_curation_choice() + combine_ticket_and_no_ticket_task = empty_task() # task dependencies + ticket_branch = create_author_create_curation_ticket_task + ( + ticket_branch + >> close_author_create_user_ticket_task + >> set_workflow_status_to_completed_task + ) + + no_ticket_branch = combine_ticket_and_no_ticket_task + ( + no_ticket_branch + >> close_author_create_user_ticket_task + >> set_workflow_status_to_completed_task + ) + + author_check_approval_branch_task >> [ticket_branch, no_ticket_branch] ( set_status_to_running_task >> create_author_on_inspire_task @@ -171,16 +192,6 @@ def set_author_create_workflow_status_to_error(**context: dict) -> None: author_check_approval_branch_task, set_workflow_status_to_error_task, ] - ( - [ - author_check_approval_branch_task - >> create_author_create_curation_ticket_task, - author_check_approval_branch_task, - ] - >> close_author_create_user_ticket_task - >> create_decision_on_curation_choice_task - >> set_workflow_status_to_completed_task - ) author_create_approved_dag() diff --git a/workflows/dags/author/author_create/author_create_rejected.py b/workflows/dags/author/author_create/author_create_rejected.py index cdd7c3f8..e492038a 100644 --- a/workflows/dags/author/author_create/author_create_rejected.py +++ b/workflows/dags/author/author_create/author_create_rejected.py @@ -2,7 +2,6 @@ from airflow.decorators import dag, task from airflow.models.param import Param -from author.author_create.shared_tasks import create_decision_on_curation_choice from hooks.backoffice.workflow_management_hook import AUTHORS, WorkflowManagementHook from hooks.backoffice.workflow_ticket_management_hook import ( WorkflowTicketManagementHook, @@ -68,15 +67,9 @@ def set_workflow_status_to_running(**context): set_status_to_running_task = set_workflow_status_to_running() close_ticket_task = close_author_create_user_ticket() set_status_completed_task = set_author_create_workflow_status_to_completed() - create_decision_on_curation_choice_task = create_decision_on_curation_choice() # task dependencies - ( - set_status_to_running_task - >> close_ticket_task - >> create_decision_on_curation_choice_task - >> set_status_completed_task - ) + set_status_to_running_task >> close_ticket_task >> set_status_completed_task author_create_rejected_dag() diff --git a/workflows/dags/author/author_create/shared_tasks.py b/workflows/dags/author/author_create/shared_tasks.py deleted file mode 100644 index 5910e264..00000000 --- a/workflows/dags/author/author_create/shared_tasks.py +++ /dev/null @@ -1,14 +0,0 @@ -from airflow.decorators import task -from hooks.backoffice.base import BackofficeHook - - -@task() -def create_decision_on_curation_choice(**context): - print("wow") - print(context) - data = { - "action": context["params"]["data"]["value"], - "workflow_id": context["params"]["workflow_id"], - } - - return BackofficeHook().request(method="POST", data=data, endpoint="api/decisions/") diff --git a/workflows/dags/author/author_create/process_until_breakpoint.py b/workflows/dags/process_until_breakpoint.py similarity index 100% rename from workflows/dags/author/author_create/process_until_breakpoint.py rename to workflows/dags/process_until_breakpoint.py diff --git a/workflows/plugins/hooks/backoffice/base.py b/workflows/plugins/hooks/backoffice/base.py index e443d4b2..7a266e30 100644 --- a/workflows/plugins/hooks/backoffice/base.py +++ b/workflows/plugins/hooks/backoffice/base.py @@ -58,11 +58,3 @@ def run( prepped_request = session.prepare_request(req) self.log.info("Sending '%s' to url: %s", method, url) return self.run_and_check(session, prepped_request, extra_options) - - def request(self, method, data, endpoint): - return self.run_with_advanced_retry( - _retry_args=self.tenacity_retry_kwargs, - method=method, - data=data, - endpoint=endpoint, - ) diff --git a/workflows/requirements-test.txt b/workflows/requirements-test.txt index de55b38d..0c69b775 100644 --- a/workflows/requirements-test.txt +++ b/workflows/requirements-test.txt @@ -1,5 +1,3 @@ pytest coverage pytest-cov -pytest-vcr==1.0.2 -vcrpy==6.0.1 diff --git a/workflows/tests/cassettes/TestAuthorCreate.test_create_decision_on_curation_choice.yaml b/workflows/tests/cassettes/TestAuthorCreate.test_create_decision_on_curation_choice.yaml deleted file mode 100644 index d739c0bd..00000000 --- a/workflows/tests/cassettes/TestAuthorCreate.test_create_decision_on_curation_choice.yaml +++ /dev/null @@ -1,50 +0,0 @@ -interactions: -- request: - body: '{"action": "create", "workflow_id": "ecaa62db-1326-43cf-8885-da96c544af42"}' - headers: - Accept: - - application/json - Accept-Encoding: - - gzip, deflate - Authorization: - - Token 2e04111a61e8f5ba6ecec52af21bbb9e81732085 - Connection: - - keep-alive - Content-Length: - - '75' - Content-Type: - - application/json - User-Agent: - - python-requests/2.31.0 - method: POST - uri: http://host.docker.internal:8000/api/decisions/ - response: - body: - string: '{"id":1,"action":"create","_created_at":"2024-08-19T15:13:28.514638Z","_updated_at":"2024-08-19T15:13:28.514646Z","user":"admin@admin.com","workflow":"ecaa62db-1326-43cf-8885-da96c544af42"}' - headers: - Allow: - - GET, POST, HEAD, OPTIONS - Content-Language: - - en - Content-Length: - - '189' - Content-Type: - - application/json - Cross-Origin-Opener-Policy: - - same-origin - Date: - - Mon, 19 Aug 2024 15:13:28 GMT - Referrer-Policy: - - same-origin - Server: - - WSGIServer/0.2 CPython/3.11.6 - Vary: - - Accept, Accept-Language, Cookie, origin - X-Content-Type-Options: - - nosniff - X-Frame-Options: - - DENY - status: - code: 201 - message: Created -version: 1