Commit a339f7a0 authored by Lionel Walter's avatar Lionel Walter
Browse files

Improve writing summary report of job

parent 7220df76
......@@ -6,7 +6,7 @@ import json
class WriteJobResultToDrupal(Resource):
def post(self, job_drupal_uuid, report):
"""
Write the job summary to Drupal job log
Write the job summary to Drupal job log (in field_summary)
---
tags:
- Drupal
......@@ -20,7 +20,7 @@ class WriteJobResultToDrupal(Resource):
- in: path
name: report
required: true
description: The report
description: The report that will be written
default: This was a huge success !
type: string
responses:
......@@ -30,7 +30,6 @@ class WriteJobResultToDrupal(Resource):
description: There was a problem
"""
# url = 'https://mb-wf1.memobase.unibas.ch/jsonapi'
headers = {
'Content-Type': 'application/vnd.api+json',
'Accept': 'application/vnd.api+json',
......@@ -39,7 +38,7 @@ class WriteJobResultToDrupal(Resource):
data = {
"data": {
"id": "2b07341f-3b99-408c-a729-6e18dd77c6d5",
"id": job_drupal_uuid,
"type": "paragraph--job_log_result",
"attributes": {
"field_summary": report
......@@ -47,11 +46,27 @@ class WriteJobResultToDrupal(Resource):
}
}
url = 'https://mb-wf1.memobase.unibas.ch/jsonapi/paragraph/' + \
'job_log_result/2b07341f-3b99-408c-a729-6e18dd77c6d5'
url = current_app.config['DRUPAL_API_URL'] + \
'/paragraph/job_log_result/' + job_drupal_uuid
requests.patch(
url,
headers=headers,
data=json.dumps(data)
)
try:
response = requests.patch(
url,
headers=headers,
data=json.dumps(data)
)
except BaseException:
current_app.logger.error(
"It was not possible to write to Drupal API via the following url " + url
)
return {
'error': 'It was not possible to write to Drupal \
API via the following url' + url
}, 500
if response.status_code == 200:
return {'message': 'Updated: '+url}, 200
elif response.status_code == 404:
return {'message': 'Not Found: '+url}, 404
else:
return {'error': 'It was not possible to write to Drupal API \
via the following url' + url}, 500
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment