我在开发环境中运行,所以这在生产中可能有所不同,但是当我从 Django Celery 运行任务时,它似乎每 10-20 秒才从代理获取任务。我现在只是在测试,但可以说我要发送大约 1000 个任务,这意味着它需要 5 个多小时才能完成。
这是正常的吗?它应该更快吗?还是我做错了什么?
这是我的任务
class SendMessage(Task):
name = "Sending SMS"
max_retries = 10
default_retry_delay = 3
def run(self, message_id, gateway_id=None, **kwargs):
logging.debug("About to send a message.")
# Because we don't always have control over transactions
# in our calling code, we will retry up to 10 times, every 3
# seconds, in order to try to allow for the commit to the database
# to finish. That gives the server 30 seconds to write all of
# the data to the database, and finish the view.
try:
message = Message.objects.get(pk=message_id)
except Exception as exc:
raise SendMessage.retry(exc=exc)
if not gateway_id:
if hasattr(message.billee, 'sms_gateway'):
gateway = message.billee.sms_gateway
else:
gateway = Gateway.objects.all()[0]
else:
gateway = Gateway.objects.get(pk=gateway_id)
#response = gateway._send(message)
print(message_id)
logging.debug("Done sending message.")
从我的角度来看
for e in Contact.objects.filter(contact_owner=request.user etc etc):
SendMessage.delay(e.id, message)