Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
I
import-api
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Jira
Jira
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
memoriav
M
Memobase 2020
S
services
import-process
import-api
Commits
e9263f57
Commit
e9263f57
authored
Jul 02, 2020
by
Lionel Walter
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update status and end time together with report summary, fix
MEMO-451
parent
b8a69cb2
Pipeline
#10906
failed with stages
in 8 minutes and 4 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
66 additions
and
4 deletions
+66
-4
import_api_app/models/Drupal.py
import_api_app/models/Drupal.py
+56
-1
import_api_app/resources/JobStart.py
import_api_app/resources/JobStart.py
+10
-3
No files found.
import_api_app/models/Drupal.py
View file @
e9263f57
from
import_api_app.models.Error
import
ImportApiError
from
flask_restful
import
current_app
from
datetime
import
datetime
import
requests
import
json
...
...
@@ -18,7 +19,8 @@ def write_results(job_log_drupal_uuid, report):
"id"
:
job_log_drupal_uuid
,
"type"
:
"paragraph--job_log_result"
,
"attributes"
:
{
"field_summary"
:
report
"field_summary"
:
report
,
"field_end_date"
:
datetime
.
utcnow
().
strftime
(
"%Y-%m-%dT%H:%M:%S+00:00"
)
}
}
}
...
...
@@ -52,3 +54,56 @@ def write_results(job_log_drupal_uuid, report):
message
=
"Unknown response status code for drupal api for url "
+
url
current_app
.
logger
.
error
(
message
)
raise
ImportApiError
(
message
)
# 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'
]
+
\
'/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
)
import_api_app/resources/JobStart.py
View file @
e9263f57
...
...
@@ -8,7 +8,7 @@ from import_api_app.models.Error import ImportApiError
from
import_api_app.resources.KafkaTopics
import
create_topics
from
import_api_app.resources.HelmStart
import
start
from
import_api_app.resources.JobReport
import
get_report
from
import_api_app.resources.WriteJobResultsToDrupal
import
write_results
from
import_api_app.resources.WriteJobResultsToDrupal
import
write_results
,
update_status
from
kubernetes
import
client
...
...
@@ -107,8 +107,10 @@ class JobStart(Resource):
return
{
'error'
:
e
.
message
},
500
FlaskThread
(
target
=
reporting
,
args
=
(
job_name
,
job_reporting_topic
,
job_parameters
[
'drupalJobLogResultUuid'
]
job_parameters
[
'drupalJobLogResultUuid'
],
job_parameters
[
'drupalJobUuid'
]
)).
start
()
return
helm_result
...
...
@@ -124,7 +126,7 @@ class FlaskThread(Thread):
super
().
run
()
def
reporting
(
job_
reporting_topic
,
drupal_job_log
_uuid
):
def
reporting
(
job_
name
,
job_reporting_topic
,
drupal_job_log_uuid
,
drupal_job
_uuid
):
# wait a bit before consuming results
time
.
sleep
(
3
)
...
...
@@ -139,3 +141,8 @@ def reporting(job_reporting_topic, drupal_job_log_uuid):
write_results
(
drupal_job_log_uuid
,
report
[
"report"
])
except
ImportApiError
as
e
:
return
{
'error'
:
e
.
message
},
500
try
:
update_status
(
drupal_job_uuid
,
job_name
)
except
ImportApiError
as
e
:
return
{
'error'
:
e
.
message
},
500
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment