延迟使用Mandrill send_at或Celery倒计时/ eta发送电子邮件 [英] Delay sending an email using Mandrill send_at or Celery countdown/eta

查看:167
本文介绍了延迟使用Mandrill send_at或Celery倒计时/ eta发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通常发送交易电子邮件来回应我网站上的某些操作,其中一些我延迟发送几个小时。实际排队邮件的功能是使用 .delay()调用的Celery任务函数,最终使用 djrill

I commonly send transactional emails in response to certain actions on my website, some of which I delay sending by a couple of hours. The function that actually queues the email is a Celery task function called with .delay() that eventually makes an API call to Mandrill using djrill.

我发现Mandrill提供了一个 send_at 参数发送一个电子邮件,将Mandrill延迟发送电子邮件,直到指定的时间。当调用 eta 或倒计时参数en / latest / reference / celery.app.task.html#celery.app.task.Task.apply_asyncrel =nofollow> apply_async() delay() ,这将使Celery工作人员在执行任务之前等待X的时间量,这在这里将是相同的。

I discovered that Mandrill offers a send_at parameter when sending an email that will have Mandrill delay sending the email until the specified time. Celery also offers eta or countdown parameters when calling apply_async() or delay() on a task, which will have the Celery worker wait X amount of time before executing the task—which here, would amount to the same thing.

忽略成本,哪种方法在架构上更可取,让Celery使用倒计时延迟排队电子邮件,或立即发送电子邮件至Mandrill但是使用 send_at 参数,所以Mandrill等待我?在做出这个决定时,我应该考虑什么因素?

Ignoring cost, which approach is architecturally preferable—having Celery delay queuing the email using countdown, or sending the email to Mandrill immediately but with a send_at parameter so Mandrill waits for me? What factors should I be considering when making this decision?

推荐答案

我将分享一些我们可以考虑的一些要点,选择这里:

I'll share some points we could have into account to make a choice here:


  1. 容错:如果我们对Celery负责,那么我们可以更容易发生故障,因为如果消息队列(Rabbitmq,ZeroMQ或其他),机器或Celery本身失败,则不会发送电子邮件。 Mandrill也可能会失败,但可能会在次要档次中。

  1. Fault tolerance: if we give this responsibility to Celery, then we could be more prone to fails, since if the message queue (Rabbitmq, ZeroMQ or whatever ), the machine or the Celery itself fails then the email will never be sent. Mandrill could fails as well, but probably in minor grade.

维护:如果您需要更换Celery ?在这种情况下,您需要迁移代码,并且可能需要花费一些时间来了解如何在新的MQ工具中执行此调度。

Maintenance: What about if you need to change Celery for something else? In this case you need to migrate the code and probably, to spend some time to figure out how to do this scheduling in the new MQ tool.

OOP :从OPP的角度来看,我们可能会看到Mandrill是一个发送电子邮件的实体,它带来了几个功能。调度,所以让我们从系统中使用这个外部服务,让它做它的工作!

OOP: From the point of OPP, we might see Mandrill as an entity that sends emails, which brings several features, e.g. scheduling, so let's consume this external service from our system, let it do it its work!

可用性和可扩展性:考虑到假设情况,您需要同时运行多个服务器的系统,因为性能要求不断提高;这是更容易和更有效的方式来处理这个调度?

Usability and Scalability: Think on an hypothetical situation where you need to run your system in more than one server simultaneously, due to growing performance requirements; which is the easier and more efficient way to handle this scheduling?

这些并不是所有应考虑的方面做出决定,但肯定是不应该错过的一些。希望有助于找出更好/坚实的解决方案。

These are not all the aspects that should be considered to make a decision, but certainly are some that should not be missed. Hope that helps to figure a better/solid solution.

这篇关于延迟使用Mandrill send_at或Celery倒计时/ eta发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆