Skip to content
Snippets Groups Projects
Commit 484aacc3a69b authored by Fabien Amarger's avatar Fabien Amarger
Browse files

feat: Store import_data log into the import_report file

parent e249808dc6cc
No related branches found
No related tags found
1 merge request!16Log import_data to S3 storage
......@@ -15,9 +15,10 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
import io
import logging
import requests
import pyshacl
from datetime import datetime
......@@ -18,9 +19,10 @@
import logging
import requests
import pyshacl
from datetime import datetime
from cubicweb import Binary
from cubicweb_rq.rq import rqjob
from rdflib import Graph
......@@ -69,6 +71,14 @@
return everything_ok, errors
def get_import_data_logger(stream_file):
log = logging.getLogger("rq.task")
handler = logging.StreamHandler(stream_file)
handler.setLevel(logging.DEBUG)
log.addHandler(handler)
return log
@rqjob
def import_data(
cnx,
......@@ -84,6 +94,8 @@
import_process = cnx.entity_from_eid(import_process_eid)
wf = import_process.cw_adapt_to("IWorkflowable")
wf.fire_transition("starts")
stream_log_file = io.StringIO()
log = get_import_data_logger(stream_log_file)
cnx.commit()
task_failed = False
formatted_exc = None
......@@ -87,7 +99,6 @@
cnx.commit()
task_failed = False
formatted_exc = None
log = logging.getLogger("rq.task")
import_recipe = import_process.import_recipe[0]
dataservice = import_recipe.dataservice[0]
import_procedure = import_process.import_procedure[0]
......@@ -111,7 +122,16 @@
task_failed = True
else:
log.info("Data was successfully validated")
# XXX PUT in S3 file
import_process.cw_set(
import_report=cnx.create_entity(
"File",
title=f"Log file for ImportProcess#{import_process_eid}",
data=Binary(stream_log_file.read().encode("utf8")),
data_name="log.txt",
data_format="plain/text",
)
)
except Exception as error:
task_failed = True
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment