[英]Is there a way to get around H12 timeouts in Heroku using griddler to parse inbound messages with large attachments from sendgrid
我的工作流程是電子郵件 - sendgrid - griddler,rails應用程序在heroku上運行。 所有入站電子郵件都有附件,有些則相當大。 我不斷在Heroku上獲得H12超時,因為附件需要超過30秒才能上傳到Google雲端存儲。
我已盡可能使用延遲工作,但我不認為我可以將附件從griddler傳遞到延遲工作,因為附件是短暫的。 我有一個朋友建議只是轉而從gmail檢索電子郵件,而不是使用sendgrid和griddler,但這比我目前正在改寫的更多。 在理想的世界里,我能夠將附件傳遞給延遲的工作,但我不知道最終是否可能。
email_processor.rb
if pdfs = attachments.select { |attachment| attachment.content_type == 'application/pdf' }
pdfs.each do |att|
# att is a ActionDispatch::Http::UploadedFile type
# content_type = MIME::Types.type_for(att.to_path).first.content_type
content_type = att.content_type
if content_type == 'application/pdf'
# later if we use multiple attachments in single fax, change num_pages
fax = @email_address.phone_number.faxes.create(sending_email: @email_address.address ,twilio_to: result, twilio_from: @email_address.phone_number.number, twilio_num_pages: 1)
attachment = fax.create_attachment
# next two rows should be with delay
attachment.upload_file!(att)
#moved to attachment model for testing
#fax.send!
end
end
file upload from another model
def upload_file!(file)
# file should be ActionDispatch::Http::UploadedFile type
filename = file.original_filename.gsub(/\s+/, '_')
filename = filename[0..15] if filename.size > 16
path = "fax/#{fax.id}/att-#{id}-#{filename}"
upload_out!(file.open, path)
#self.fax.send!
#make_thumbnail_pdf!(file.open)
end
def upload_out!(file, path)
upload = StorageBucket.files.new key: path, body: file, public: true
upload.save # upload file
update_columns url: upload.public_url
self.fax.update(status: 'outbound-uploaded')
self.fax.process!
end
如果您無法在30秒內收到並上傳附件,則heroku將無法接收電子郵件。 你是對的 - 網絡dyno的臨時存儲無法從工作dyno運行延遲工作訪問。
即使工作人員dyno可以從web dyno的短暫存儲中讀取數據,也不能保證web dyno能夠在30秒內從sendgrid處理POST,如果附件足夠大的話。
一種選擇是配置sendgrid以將電子郵件直接轉發到您的Google應用引擎 - https://cloud.google.com/appengine/docs/standard/python/mail/receiving-mail-with-mail-api
您的應用引擎腳本可以將附件寫入谷歌雲存儲,然后您的應用引擎腳本可以使用附件的位置對您的heroku應用進行POST,然后Web應用可以將延遲的作業排隊以下載和處理附件。
我最終完全重寫了我的電子郵件處理。 我將gmail設置為郵件目標,然后使用Heroku的計划任務處理電子郵件(查找未讀),然后將附件上傳到Google雲端存儲。 使用計划任務可以解決H12問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.