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

Commit

Permalink
airflow wf: close curation not working fix
Browse files Browse the repository at this point in the history
  • Loading branch information
DonHaul committed Aug 27, 2024
1 parent a6cbbf8 commit b8ea808
Show file tree
Hide file tree
Showing 9 changed files with 131 additions and 30 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test-workflows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
-v "$(pwd)"/tests:/opt/airflow/tests
-v "$(pwd)"/requirements-test.txt:/opt/airflow/requirements-test.txt
-v "$(pwd)"/data:/opt/airflow/data
-v "$(pwd)"/scripts/variables/variables.json:/opt/airflow/variables.json
-v "$(pwd)"/scripts:/opt/airflow/scripts
-e AIRFLOW__CORE__EXECUTOR=CeleryExecutor
-e AIRFLOW__DATABASE__SQL_ALCHEMY_CONN=postgresql+psycopg2://airflow:[email protected]:5432/airflow
-e AIRFLOW__CELERY__RESULT_BACKEND=db+postgresql://airflow:[email protected]:5432/airflow
Expand All @@ -61,4 +61,4 @@ jobs:
-e AIRFLOW__CORE__LOAD_EXAMPLES="false"
-e AIRFLOW__API__AUTH_BACKENDS="airflow.api.auth.backend.basic_auth,airflow.api.auth.backend.session"
registry.cern.ch/cern-sis/inspire/workflows@${{ needs.build.outputs.image-id }}
bash -c "pip install -r requirements-test.txt && airflow db init && airflow variables import /opt/airflow/variables.json && pytest /opt/airflow/tests"
bash -c "pip install -r requirements-test.txt && airflow db init && airflow connections import /opt/airflow/scripts/connections/connections.json && airflow variables import /opt/airflow/scripts/variables/variables.json && pytest /opt/airflow/tests"
2 changes: 1 addition & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ x-airflow-common: &airflow-common
AIRFLOW__CELERY__RESULT_BACKEND: db+postgresql://airflow:airflow@postgres-airflow/airflow
AIRFLOW__CELERY__BROKER_URL: redis://:@redis:6379/0
AIRFLOW__CORE__FERNET_KEY: ""
AIRFLOW__CORE__DAGS_ARE_PAUSED_AT_CREATION: "true"
AIRFLOW__CORE__DAGS_ARE_PAUSED_AT_CREATION: "false"
AIRFLOW__CORE__LOAD_EXAMPLES: "false"
AIRFLOW__API__AUTH_BACKENDS: "airflow.api.auth.backend.basic_auth,airflow.api.auth.backend.session"
AIRFLOW__WEBSERVER__RELOAD_ON_PLUGIN_CHANGE: "true" # used when modifying plugins
Expand Down
12 changes: 1 addition & 11 deletions workflows/dags/author/author_create/author_create_approved.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

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 close_author_create_user_ticket
from hooks.backoffice.workflow_management_hook import AUTHORS, WorkflowManagementHook
from hooks.backoffice.workflow_ticket_management_hook import (
WorkflowTicketManagementHook,
Expand Down Expand Up @@ -119,16 +119,6 @@ def author_create_success_branch(**context: dict) -> str:
else:
return "set_author_create_workflow_status_to_error"

@task(trigger_rule=TriggerRule.NONE_FAILED_MIN_ONE_SUCCESS)
def close_author_create_user_ticket(**context: dict) -> None:
ticket_type = "author_create_user"
ticket_id = workflow_ticket_management_hook.get_ticket(
workflow_id=context["params"]["workflow_id"], ticket_type=ticket_type
)["ticket_id"]
endpoint = "api/tickets/resolve"
request_data = {"ticket_id": ticket_id}
inspire_http_hook.call_api(endpoint=endpoint, data=request_data, method="POST")

@task()
def set_author_create_workflow_status_to_completed(**context: dict) -> None:
status_name = "completed"
Expand Down
17 changes: 1 addition & 16 deletions workflows/dags/author/author_create/author_create_rejected.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@

from airflow.decorators import dag, task
from airflow.models.param import Param
from author.author_create.shared_tasks import close_author_create_user_ticket
from hooks.backoffice.workflow_management_hook import AUTHORS, WorkflowManagementHook
from hooks.backoffice.workflow_ticket_management_hook import (
WorkflowTicketManagementHook,
)
from hooks.inspirehep.inspire_http_hook import InspireHttpHook
from include.utils.set_workflow_status import set_workflow_status_to_error


Expand All @@ -31,19 +28,7 @@ def author_create_rejected_dag() -> None:
2. set_author_create_workflow_status_to_completed: Sets the status of
the author creation workflow to 'completed'.
"""
inspire_http_hook = InspireHttpHook()
workflow_management_hook = WorkflowManagementHook()
workflow_ticket_management_hook = WorkflowTicketManagementHook()

@task()
def close_author_create_user_ticket(**context: dict) -> None:
ticket_type = "author_create_user"
ticket_id = workflow_ticket_management_hook.get_ticket(
workflow_id=context["params"]["workflow_id"], ticket_type=ticket_type
)["ticket_id"]
endpoint = "/tickets/resolve" # TODO: the URL for resolving dag will change
request_data = {"ticket_id": ticket_id}
inspire_http_hook.call_api(endpoint=endpoint, data=request_data, method="POST")

@task()
def set_author_create_workflow_status_to_completed(**context: dict) -> None:
Expand Down
17 changes: 17 additions & 0 deletions workflows/dags/author/author_create/shared_tasks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from airflow.decorators import task
from airflow.utils.trigger_rule import TriggerRule
from hooks.backoffice.workflow_ticket_management_hook import (
WorkflowTicketManagementHook,
)
from hooks.inspirehep.inspire_http_hook import InspireHttpHook


@task(trigger_rule=TriggerRule.NONE_FAILED_MIN_ONE_SUCCESS)
def close_author_create_user_ticket(**context: dict) -> None:
ticket_type = "author_create_user"
ticket_id = WorkflowTicketManagementHook().get_ticket(
workflow_id=context["params"]["workflow_id"], ticket_type=ticket_type
)["ticket_id"]
endpoint = "api/tickets/resolve"
request_data = {"ticket_id": ticket_id}
InspireHttpHook().call_api(endpoint=endpoint, data=request_data, method="POST")
2 changes: 2 additions & 0 deletions workflows/requirements-test.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
pytest
coverage
pytest-cov
pytest-vcr==1.0.2
vcrpy==6.0.1
Empty file added workflows/tests/__init__.py
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
interactions:
- request:
body: null
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate
Authorization:
- Token 2e04111a61e8f5ba6ecec52af21bbb9e81732085
Connection:
- keep-alive
Content-Type:
- application/json
User-Agent:
- python-requests/2.31.0
method: GET
uri: http://host.docker.internal:8000/api/workflow-ticket/f8301c06-8fa1-4124-845e-c270b910af5f/?ticket_type=author_create_user
response:
body:
string: '{"id":1,"ticket_url":"https://cerntraining.service-now.com/nav_to.do?uri=/u_request_fulfillment.do?sys_id=656f2d17878c929095f833340cbb3531","ticket_id":"656f2d17878c929095f833340cbb3531","ticket_type":"author_create_user","workflow_id":"f8301c06-8fa1-4124-845e-c270b910af5f"}'
headers:
Allow:
- GET, HEAD, OPTIONS
Content-Language:
- en
Content-Length:
- '275'
Content-Type:
- application/json
Cross-Origin-Opener-Policy:
- same-origin
Date:
- Wed, 21 Aug 2024 11:06:38 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: 200
message: OK
- request:
body: ticket_id=656f2d17878c929095f833340cbb3531
headers:
Accept:
- application/vnd+inspire.record.raw+json
Accept-Encoding:
- gzip, deflate
Authorization:
- Bearer cZiS4W7K8sqyebkxQzpnSwuUKLr5Ne6qPfnoOAjP7M2IvHxQhKmwiCJpp2QC
Connection:
- keep-alive
Content-Length:
- '42'
Content-Type:
- application/x-www-form-urlencoded
User-Agent:
- python-requests/2.31.0
method: POST
uri: https://inspirebeta.net/api/tickets/resolve
response:
body:
string: '{"message":"Ticket resolved"}
'
headers:
access-control-allow-origin:
- '*'
access-control-expose-headers:
- Content-Type, ETag, Link, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset
content-length:
- '30'
content-type:
- application/json
date:
- Wed, 21 Aug 2024 11:06:39 GMT
server:
- gunicorn/19.10.0
x-proxy-backend:
- inspire-qa_hep-web_http
status:
code: 200
message: OK
version: 1
17 changes: 17 additions & 0 deletions workflows/tests/test_author_create_tasks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import pytest
from dags.author.author_create.shared_tasks import (
close_author_create_user_ticket,
)


class TestAuthorCreate:
context = {
"params": {
"workflow_id": "f8301c06-8fa1-4124-845e-c270b910af5f",
"data": {"value": "reject", "create_ticket": False},
}
}

@pytest.mark.vcr()
def test_close_author_create_user_ticket(self):
close_author_create_user_ticket.function(**self.context)

0 comments on commit b8ea808

Please sign in to comment.