Commit 8c2d2fb8 authored by Matthias's avatar Matthias
Browse files

cleanup code

parent fbda99b0
Pipeline #24105 passed with stages
in 3 minutes and 20 seconds
......@@ -113,7 +113,7 @@ def write_results(job_drupal_uuid, job_log_drupal_uuid, status, report):
current_app.logger.error(message)
raise ImportApiError(message)
if response.status_code == 200:
current_app.logger.debug('Updated: '+url)
current_app.logger.debug('Updated: ' + url)
returnVal['message'] += 'Updated: ' + url + '\n'
elif response.status_code == 403:
message = "Not authorized to write to: " + url
......@@ -128,56 +128,3 @@ def write_results(job_drupal_uuid, job_log_drupal_uuid, status, report):
current_app.logger.error(message)
raise ImportApiError(message)
return returnVal
# make the job as not active any more and write the end data
# todo refactor this in a more generic function
def update_status(job_drupal_uuid, job_name):
# in drupal job names have underscore instead of minus
job_name = job_name.replace("-", "_")
current_app.logger.debug("uuid to write: " + job_drupal_uuid)
headers = {
'Content-Type': 'application/vnd.api+json',
'Accept': 'application/vnd.api+json',
'X-API-Key': current_app.config['drupal-api-key']
}
data = {
"data": {
"id": job_drupal_uuid,
"type": "paragraph--job_"+job_name,
"attributes": {
"field_is_active": False
}
}
}
url = current_app.config['drupal-api-url'] + \
'/jsonapi/paragraph/job_'+job_name+'/' + job_drupal_uuid
try:
response = requests.patch(
url,
headers=headers,
data=json.dumps(data)
)
except requests.exceptions.RequestException:
message = "It was not possible to write to Drupal API \
via the following url " + url
current_app.logger.error(message)
raise ImportApiError(message)
if response.status_code == 200:
current_app.logger.error('Updated: '+url)
return {'message': 'Updated: ' + url}
elif response.status_code == 403:
message = "Not authorized to write to: " + url
current_app.logger.error(message)
raise ImportApiError(message)
elif response.status_code == 404:
message = 'Not Found: ' + url
current_app.logger.error(message)
raise ImportApiError(message)
else:
message = "Unknown response status code for drupal api for url " + url
current_app.logger.error(message)
raise ImportApiError(message)
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