From 7e3c47f8bfec83d25f5e518ca6a31d353eb3c5b6 Mon Sep 17 00:00:00 2001 From: mike cullerton Date: Fri, 22 Oct 2021 12:52:43 -0400 Subject: [PATCH 1/2] Added timestamp, and now return a schema just like the do_task method --- crc/scripts/email.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/crc/scripts/email.py b/crc/scripts/email.py index 22f51e21..b732d2ea 100644 --- a/crc/scripts/email.py +++ b/crc/scripts/email.py @@ -12,6 +12,8 @@ from crc.services.email_service import EmailService from crc.services.ldap_service import LdapService from crc.services.study_service import StudyService +import datetime + class Email(Script): """Send an email from a script task, as part of a workflow. @@ -43,7 +45,12 @@ email(subject="My Subject", recipients="user@example.com", attachments=['Study_A subject = self.get_subject(kwargs['subject']) recipients = self.get_email_addresses(kwargs['recipients'], study_id) content, content_html = EmailService().get_rendered_content(task.task_spec.documentation, task.data) - return EmailModel(subject=subject, recipients=recipients, content=content, content_html=content_html) + email_model = EmailModel(subject=subject, + recipients=recipients, + content=content, + content_html=content_html, + timestamp=datetime.datetime.utcnow()) + return EmailModelSchema().dump(email_model) def do_task(self, task, study_id, workflow_id, *args, **kwargs): From a7fcaac5ef4a9a56f512f451871c86b4910c8bfb Mon Sep 17 00:00:00 2001 From: mike cullerton Date: Fri, 22 Oct 2021 12:53:26 -0400 Subject: [PATCH 2/2] Better messaging for the configurators. We were generating 500 errors here --- crc/services/workflow_service.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/crc/services/workflow_service.py b/crc/services/workflow_service.py index 86cdff2f..80cdd020 100755 --- a/crc/services/workflow_service.py +++ b/crc/services/workflow_service.py @@ -282,7 +282,12 @@ class WorkflowService(object): # jsonify, and de-jsonify the data to mimic how data will be returned from the front end for forms and assures # we aren't generating something that can't be serialized. - form_data_string = json.dumps(form_data) + try: + form_data_string = json.dumps(form_data) + except TypeError as te: + raise ApiError.from_task(code='serialize_error', + message=f'Something cannot be serialized. Message is: {te}', + task=task) task.data.update(json.loads(form_data_string)) @staticmethod