From 765503ab62f661da9c47ec65654471f9030442b7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9rome=20Perrin?= <jerome@nexedi.com>
Date: Mon, 8 Feb 2016 06:52:54 +0000
Subject: [PATCH] erp5_short_message: activate call to portal_sms.send

This way it is isolated it in a transaction that is less likely to fail. Activate with max_retry=0 and conflict_retry=False not to send activity twice in case of error.
As with email, if there was an error in activity processing, it is advised to investigate the transport logs to see if message was send or not.
---
 .../erp5_short_message/ShortMessage_send.py      | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/bt5/erp5_short_message/SkinTemplateItem/portal_skins/erp5_short_message/ShortMessage_send.py b/bt5/erp5_short_message/SkinTemplateItem/portal_skins/erp5_short_message/ShortMessage_send.py
index e0a08ae5f7..4c5b1615cb 100644
--- a/bt5/erp5_short_message/SkinTemplateItem/portal_skins/erp5_short_message/ShortMessage_send.py
+++ b/bt5/erp5_short_message/SkinTemplateItem/portal_skins/erp5_short_message/ShortMessage_send.py
@@ -29,5 +29,17 @@ if not body:
 if not context.getStartDate():
   context.setStartDate(DateTime())
 
-context.portal_sms.send(text=body,recipient=to_url,sender=from_url,sender_title=from_title,message_type="text",
-                        test=download, document_relative_url=context.getRelativeUrl(), **kw)
+context.portal_sms.activate(
+  activity="SQLQueue",
+  # We do not retry these activities not to send SMS multiple times
+  max_retry=0,
+  conflict_retry=False,
+).send(
+  text=body,
+  recipient=to_url,
+  sender=from_url,
+  sender_title=from_title,
+  message_type="text",
+  test=download,
+  document_relative_url=context.getRelativeUrl(),
+  **kw)
-- 
2.30.9