我正在使用django_notification模塊。 https://github.com/pinax/django-notification/blob/master/docs/usage.txt我不明白這個Django文檔。我如何使用它這個模塊?
這是我在我的代碼做發送電子郵件給用戶,當有事情發生:
notification.send([to_user], "comment_received", noti_dict)
但是,這似乎阻止請求。發送出去需要很長時間。我閱讀了文檔,它說可以將它添加到隊列中(異步)。我如何將它添加到異步隊列?
我不明白這些文檔試圖說什麼。什麼是「emit_notices」?我什麼時候打電話?我有一個腳本每5秒調用一次嗎?這很愚蠢。什麼是異步執行的正確方法?我該怎麼辦?
Lets first break down what each does.
``send_now``
~~~~~~~~~~~~
This is a blocking call that will check each user for elgibility of the
notice and actually peform the send.
``queue``
~~~~~~~~~
This is a non-blocking call that will queue the call to ``send_now`` to
be executed at a later time. To later execute the call you need to use
the ``emit_notices`` management command.
``send``
~~~~~~~~
A proxy around ``send_now`` and ``queue``. It gets its behavior from a global
setting named ``NOTIFICATION_QUEUE_ALL``. By default it is ``False``. This
setting is meant to help control whether you want to queue any call to
``send``.
``send`` also accepts ``now`` and ``queue`` keyword arguments. By default
each option is set to ``False`` to honor the global setting which is ``False``.
This enables you to override on a per call basis whether it should call
``send_now`` or ``queue``.