之前,SendGrid 事件 webhook 发送了不正确的批处理 JSON,文档由换行符分隔:
{ "email": "john.doe@sendgrid.com", "timestamp": 1337197600, "smtp-id": "<4FB4041F.6080505@sendgrid.com>", "event": "processed" }
{ "email": "john.doe@sendgrid.com", "timestamp": 1337966815, "category": "newuser", "event": "click", "url": "http://sendgrid.com" }
{ "email": "john.doe@sendgrid.com", "timestamp": 1337969592, "smtp-id": "<20120525181309.C1A9B40405B3@Example-Mac.local>", "event": "processed" }
今天,它使用v3 发送正确的 JSON:
[
{
"email": "john.doe@sendgrid.com",
"timestamp": 1337197600,
"smtp-id": "<4FB4041F.6080505@sendgrid.com>",
"event": "processed"
},
{
"email": "john.doe@sendgrid.com",
"timestamp": 1337966815,
"category": "newuser",
"event": "click",
"url": "http://sendgrid.com"
},
{
"email": "john.doe@sendgrid.com",
"timestamp": 1337969592,
"smtp-id": "<20120525181309.C1A9B40405B3@Example-Mac.local>",
"event": "processed"
}
]
如果您之前一直在处理非批处理事件,则需要调整您的代码,以便它解释一个数组,而不仅仅是一个文档,然后循环遍历该数组。放入代码:
# This
consume_data(params)
# Becomes this
params.each { |doc|
consume_data(doc)
}