Skip to content

Commit

Permalink
workflows: fix author submissions not erroring
Browse files Browse the repository at this point in the history
also some small config fixes for easy testing with docker

* ref: cern-sis/issues-inspire#643
  • Loading branch information
DonHaul committed Dec 19, 2024
1 parent 3942899 commit 0c9df55
Show file tree
Hide file tree
Showing 11 changed files with 1,476 additions and 8 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ run: services start-inspirehep sleep setup-inspirehep start-backoffice sleep set
run-inspirehep: services start-inspirehep sleep setup-inspirehep
run-backoffice: services start-backoffice sleep setup-backoffice

start: services start-inspirehep start-backoffice

start-inspirehep:
echo -e "\033[0;32m Starting HEP. \033[0m"
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ Then depending on the service you are testing:
- inspire-hep: ?
- backend: ?

### Adding global variables:
There are two ways of setting environment variables on hep:
- `backend/inspirehep/config.py`
- `docker-compose.services.yml` - `INVENIO_` prefix must be added. Variables here overwrite `config.py`

## Running Locally
For running the enviroment locally you have the following prerequirements:

Expand Down
2 changes: 2 additions & 0 deletions docker-compose.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ services:
- 'INVENIO_SECRET_KEY=CHANGE_ME'
- 'INVENIO_SQLALCHEMY_DATABASE_URI=postgresql+psycopg2://inspirehep:inspirehep@db:5432/inspirehep'
- 'INVENIO_INSPIRE_NEXT_URL=http://ui:8080'
- 'INVENIO_INSPIRE_BACKOFFICE_URL=http://host.docker.internal:8001'
- 'INVENIO_AUTHENTICATION_TOKEN_BACKOFFICE=2e04111a61e8f5ba6ecec52af21bbb9e81732085'
cache:
image: redis:5-alpine
restart: 'always'
Expand Down
3 changes: 2 additions & 1 deletion workflows/dags/author/author_create/author_create_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@
params={
"workflow_id": Param(type="string", default=""),
"data": Param(type="object", default={}),
"collection": Param(type="string", default=AUTHORS),
},
start_date=datetime.datetime(2024, 5, 5),
schedule=None,
catchup=False,
# TODO: what if callback fails? Data in backoffice not up to date!
on_failure_callback=set_workflow_status_to_error,
tags=["authors"],
tags=[AUTHORS],
)
def author_create_initialization_dag():
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def update_workflow(self, workflow_id: str, workflow_data: dict) -> Response:
return self.run_with_advanced_retry(
_retry_args=self.tenacity_retry_kwargs,
method="PUT",
data=workflow_data,
json=workflow_data,
endpoint=endpoint,
)

Expand All @@ -61,6 +61,6 @@ def partial_update_workflow(
return self.run_with_advanced_retry(
_retry_args=self.tenacity_retry_kwargs,
method="PATCH",
data=workflow_partial_update_data,
json=workflow_partial_update_data,
endpoint=endpoint,
)
10 changes: 5 additions & 5 deletions workflows/plugins/include/utils/set_workflow_status.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging

from hooks.backoffice.workflow_management_hook import AUTHORS, WorkflowManagementHook
from hooks.backoffice.workflow_management_hook import WorkflowManagementHook
from requests import Response

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -36,10 +36,10 @@ def set_workflow_status_to_error(context: dict) -> None:
workflow_id (str): The identifier for the workflow.
"""
logger.info("Setting workflow status to error")
response = WorkflowManagementHook().set_workflow_status(
status_name="error",
workflow_id=context["params"]["workflow_id"],
collection=AUTHORS,
response = WorkflowManagementHook(
collection=context["params"]["collection"]
).set_workflow_status(
status_name="error", workflow_id=context["params"]["workflow_id"]
)
try:
response.raise_for_status()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,282 @@
interactions:
- request:
body: '{"status": "running"}'
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
Content-Length:
- '21'
Content-Type:
- application/json
method: PATCH
uri: http://host.docker.internal:8001/api/workflows/authors/00000000-0000-0000-0000-000000001521/
response:
body:
string: '{"id":"00000000-0000-0000-0000-000000001521","tickets":[],"decisions":[],"data":{"name":{"value":"B,
Third","preferred_name":"Third B"},"status":"departed","_collections":["Authors"],"acquisition_source":{"email":"[email protected]","orcid":"0000-0000-0000-0000","method":"submitter","source":"submitter","datetime":"2024-11-18T11:34:19.809575","internal_uid":50872}},"workflow_type":"AUTHOR_CREATE","status":"running","_created_at":"2024-11-25T13:49:53.009000Z","_updated_at":"2024-12-18T16:53:36.849446Z"}'
headers:
Allow:
- GET, PUT, PATCH, DELETE, HEAD, OPTIONS
Content-Language:
- en
Content-Length:
- '502'
Content-Type:
- application/json
Cross-Origin-Opener-Policy:
- same-origin
Date:
- Wed, 18 Dec 2024 16:53:37 GMT
Referrer-Policy:
- same-origin
Server:
- WSGIServer/0.2 CPython/3.11.6
Server-Timing:
- TimerPanel_utime;dur=89.91899999999475;desc="User CPU time", TimerPanel_stime;dur=0.9880000000066502;desc="System
CPU time", TimerPanel_total;dur=90.9070000000014;desc="Total CPU time", TimerPanel_total_time;dur=244.1654999856837;desc="Elapsed
time", SQLPanel_sql_time;dur=4.612791002728045;desc="SQL 10 queries", CachePanel_total_time;dur=0;desc="Cache
0 Calls"
Vary:
- Accept, Accept-Language, Cookie, origin
X-Content-Type-Options:
- nosniff
X-Frame-Options:
- DENY
djdt-store-id:
- e27d9e4cd8a9424788412023de5a52f0
status:
code: 200
message: OK
- request:
body: '{"status": "error"}'
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
Content-Length:
- '19'
Content-Type:
- application/json
method: PATCH
uri: http://host.docker.internal:8001/api/workflows/authors/00000000-0000-0000-0000-000000001521/
response:
body:
string: '{"id":"00000000-0000-0000-0000-000000001521","tickets":[],"decisions":[],"data":{"name":{"value":"B,
Third","preferred_name":"Third B"},"status":"departed","_collections":["Authors"],"acquisition_source":{"email":"[email protected]","orcid":"0000-0000-0000-0000","method":"submitter","source":"submitter","datetime":"2024-11-18T11:34:19.809575","internal_uid":50872}},"workflow_type":"AUTHOR_CREATE","status":"error","_created_at":"2024-11-25T13:49:53.009000Z","_updated_at":"2024-12-18T16:53:37.094582Z"}'
headers:
Allow:
- GET, PUT, PATCH, DELETE, HEAD, OPTIONS
Content-Language:
- en
Content-Length:
- '500'
Content-Type:
- application/json
Cross-Origin-Opener-Policy:
- same-origin
Date:
- Wed, 18 Dec 2024 16:53:37 GMT
Referrer-Policy:
- same-origin
Server:
- WSGIServer/0.2 CPython/3.11.6
Server-Timing:
- TimerPanel_utime;dur=25.058999999998832;desc="User CPU time", TimerPanel_stime;dur=0.0;desc="System
CPU time", TimerPanel_total;dur=25.058999999998832;desc="Total CPU time",
TimerPanel_total_time;dur=53.21687500691041;desc="Elapsed time", SQLPanel_sql_time;dur=3.2330840185750276;desc="SQL
10 queries", CachePanel_total_time;dur=0;desc="Cache 0 Calls"
Vary:
- Accept, Accept-Language, Cookie, origin
X-Content-Type-Options:
- nosniff
X-Frame-Options:
- DENY
djdt-store-id:
- 4231b748fadd4716bd87f0d3a7e33ee9
status:
code: 200
message: OK
- request:
body: null
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
Content-Type:
- application/json
method: GET
uri: http://host.docker.internal:8001/api/workflows/authors/00000000-0000-0000-0000-000000001521
response:
body:
string: ''
headers:
Connection:
- close
Content-Language:
- en
Content-Type:
- text/html; charset=utf-8
Cross-Origin-Opener-Policy:
- same-origin
Date:
- Wed, 18 Dec 2024 16:53:37 GMT
Location:
- /api/workflows/authors/00000000-0000-0000-0000-000000001521/
Referrer-Policy:
- same-origin
Server:
- WSGIServer/0.2 CPython/3.11.6
Vary:
- Accept-Language, Cookie, origin
X-Content-Type-Options:
- nosniff
status:
code: 301
message: Moved Permanently
- request:
body: null
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
method: GET
uri: http://host.docker.internal:8001/api/workflows/authors/00000000-0000-0000-0000-000000001521/
response:
body:
string: '{"id":"00000000-0000-0000-0000-000000001521","tickets":[],"decisions":[],"validation_errors":[],"data":{"name":{"value":"B,
Third","preferred_name":"Third B"},"status":"departed","_collections":["Authors"],"acquisition_source":{"email":"[email protected]","orcid":"0000-0000-0000-0000","method":"submitter","source":"submitter","datetime":"2024-11-18T11:34:19.809575","internal_uid":50872}},"workflow_type":"AUTHOR_CREATE","status":"error","_created_at":"2024-11-25T13:49:53.009000Z","_updated_at":"2024-12-18T16:53:37.094582Z"}'
headers:
Allow:
- GET, PUT, PATCH, DELETE, HEAD, OPTIONS
Content-Language:
- en
Content-Length:
- '523'
Content-Type:
- application/json
Cross-Origin-Opener-Policy:
- same-origin
Date:
- Wed, 18 Dec 2024 16:53:37 GMT
Referrer-Policy:
- same-origin
Server:
- WSGIServer/0.2 CPython/3.11.6
Server-Timing:
- TimerPanel_utime;dur=21.40500000000145;desc="User CPU time", TimerPanel_stime;dur=0.927000000004341;desc="System
CPU time", TimerPanel_total;dur=22.33200000000579;desc="Total CPU time", TimerPanel_total_time;dur=26.116458990145475;desc="Elapsed
time", SQLPanel_sql_time;dur=3.307167993625626;desc="SQL 12 queries", CachePanel_total_time;dur=0;desc="Cache
0 Calls"
Vary:
- Accept, Accept-Language, Cookie, origin
X-Content-Type-Options:
- nosniff
X-Frame-Options:
- DENY
djdt-store-id:
- f4637e2a26094b3fab8bf6ad4a3504c1
status:
code: 200
message: OK
- request:
body: null
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
Content-Type:
- application/json
method: GET
uri: http://host.docker.internal:8001/api/workflows/authors/00000000-0000-0000-0000-000000001521
response:
body:
string: ''
headers:
Connection:
- close
Content-Language:
- en
Content-Type:
- text/html; charset=utf-8
Cross-Origin-Opener-Policy:
- same-origin
Date:
- Wed, 18 Dec 2024 16:53:37 GMT
Location:
- /api/workflows/authors/00000000-0000-0000-0000-000000001521/
Referrer-Policy:
- same-origin
Server:
- WSGIServer/0.2 CPython/3.11.6
Vary:
- Accept-Language, Cookie, origin
X-Content-Type-Options:
- nosniff
status:
code: 301
message: Moved Permanently
- request:
body: null
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
method: GET
uri: http://host.docker.internal:8001/api/workflows/authors/00000000-0000-0000-0000-000000001521/
response:
body:
string: '{"id":"00000000-0000-0000-0000-000000001521","tickets":[],"decisions":[],"validation_errors":[],"data":{"name":{"value":"B,
Third","preferred_name":"Third B"},"status":"departed","_collections":["Authors"],"acquisition_source":{"email":"[email protected]","orcid":"0000-0000-0000-0000","method":"submitter","source":"submitter","datetime":"2024-11-18T11:34:19.809575","internal_uid":50872}},"workflow_type":"AUTHOR_CREATE","status":"error","_created_at":"2024-11-25T13:49:53.009000Z","_updated_at":"2024-12-18T16:53:37.094582Z"}'
headers:
Allow:
- GET, PUT, PATCH, DELETE, HEAD, OPTIONS
Content-Language:
- en
Content-Length:
- '523'
Content-Type:
- application/json
Cross-Origin-Opener-Policy:
- same-origin
Date:
- Wed, 18 Dec 2024 16:53:37 GMT
Referrer-Policy:
- same-origin
Server:
- WSGIServer/0.2 CPython/3.11.6
Server-Timing:
- TimerPanel_utime;dur=19.293999999987932;desc="User CPU time", TimerPanel_stime;dur=3.731000000001927;desc="System
CPU time", TimerPanel_total;dur=23.02499999998986;desc="Total CPU time", TimerPanel_total_time;dur=27.19899997464381;desc="Elapsed
time", SQLPanel_sql_time;dur=3.820874000666663;desc="SQL 12 queries", CachePanel_total_time;dur=0;desc="Cache
0 Calls"
Vary:
- Accept, Accept-Language, Cookie, origin
X-Content-Type-Options:
- nosniff
X-Frame-Options:
- DENY
djdt-store-id:
- 8887d70a0b23425ca85d6fb91fc63a3b
status:
code: 200
message: OK
version: 1
Loading

0 comments on commit 0c9df55

Please sign in to comment.