Skip to content

Instantly share code, notes, and snippets.

@ask
Forked from hamsolodev/gist:451109
Created June 24, 2010 07:46
Show Gist options
  • Select an option

  • Save ask/451126 to your computer and use it in GitHub Desktop.

Select an option

Save ask/451126 to your computer and use it in GitHub Desktop.

Revisions

  1. ask revised this gist Jun 24, 2010. 1 changed file with 31 additions and 22 deletions.
    53 changes: 31 additions & 22 deletions gistfile2.pyw
    Original file line number Diff line number Diff line change
    @@ -1,22 +1,31 @@
    from carrot.connection import DjangoBrokerConnection
    from carrot.messaging import Publisher, Consumer
    connection = DjangoBrokerConnection()
    publisher = Publisher(connection=connection, exchange="sendemail", routing_key="sendemail_emails")
    publisher.send({'email': '[email protected]'})
    publisher.send({'email': '[email protected]'})
    publisher.send({'email': '[email protected]'})
    publisher.send({'email': '[email protected]'})
    publisher.send({'email': '[email protected]'})
    publisher.send({'email': '[email protected]'})
    publisher.send({'email': '[email protected]'})
    publisher.send({'email': '[email protected]'})
    publisher.send({'email': '[email protected]'})
    publisher.send({'email': '[email protected]'})
    publisher.send({'email': '[email protected]'})
    publisher.send({'email': '[email protected]'})
    publisher.send({'email': '[email protected]'})
    publisher.send({'email': '[email protected]'})
    publisher.send({'email': '[email protected]'})
    publisher.send({'email': '[email protected]'})
    publisher.close()
    connection.close()
    >>> from tasks import send_emails, process_emails
    >>> send_emails.delay()
    <AsyncResult: 4e136dc4-2757-4fce-89a1-4705b5153587>
    >>> process_emails.delay()
    <AsyncResult: 600f8117-77e1-43b3-9fb8-ca0988fd335d>


    [2010-06-24 09:46:04,176: INFO/MainProcess] Got task from broker: tasks.send_emails[c2883ef7-d63e-4060-bd92-883092b50de9]
    [2010-06-24 09:46:04,287: INFO/MainProcess] Task tasks.send_emails[c2883ef7-d63e-4060-bd92-883092b50de9] processed: None
    [2010-06-24 09:46:09,590: INFO/MainProcess] Got task from broker: tasks.process_emails[154dcac0-3593-49a0-a7f5-2a5b4aa4f5c0]
    [2010-06-24 09:46:09,655: WARNING/PoolWorker-2] boo
    [2010-06-24 09:46:09,656: WARNING/PoolWorker-2] Message: <carrot.backends.pyamqplib.Message object at 0x1022a3750>
    [2010-06-24 09:46:09,657: WARNING/PoolWorker-2] boo
    [2010-06-24 09:46:09,657: WARNING/PoolWorker-2] Message: <carrot.backends.pyamqplib.Message object at 0x1022a3950>
    [2010-06-24 09:46:09,657: WARNING/PoolWorker-2] boo
    [2010-06-24 09:46:09,658: WARNING/PoolWorker-2] Message: <carrot.backends.pyamqplib.Message object at 0x1022a38d0>
    [2010-06-24 09:46:09,658: WARNING/PoolWorker-2] boo
    [2010-06-24 09:46:09,658: WARNING/PoolWorker-2] Message: <carrot.backends.pyamqplib.Message object at 0x1022a39d0>
    [2010-06-24 09:46:09,659: WARNING/PoolWorker-2] boo
    [2010-06-24 09:46:09,659: WARNING/PoolWorker-2] Message: <carrot.backends.pyamqplib.Message object at 0x1022a3990>
    [2010-06-24 09:46:09,660: WARNING/PoolWorker-2] boo
    [2010-06-24 09:46:09,660: WARNING/PoolWorker-2] Message: <carrot.backends.pyamqplib.Message object at 0x1022a3890>
    [2010-06-24 09:46:09,661: WARNING/PoolWorker-2] boo
    [2010-06-24 09:46:09,661: WARNING/PoolWorker-2] Message: <carrot.backends.pyamqplib.Message object at 0x1022a3910>
    [2010-06-24 09:46:09,661: WARNING/PoolWorker-2] boo
    [2010-06-24 09:46:09,661: WARNING/PoolWorker-2] Message: <carrot.backends.pyamqplib.Message object at 0x1022a3750>
    [2010-06-24 09:46:09,662: WARNING/PoolWorker-2] boo
    [2010-06-24 09:46:09,662: WARNING/PoolWorker-2] Message: <carrot.backends.pyamqplib.Message object at 0x1022a3950>
    [2010-06-24 09:46:09,663: WARNING/PoolWorker-2] boo
    [2010-06-24 09:46:09,663: WARNING/PoolWorker-2] Message: <carrot.backends.pyamqplib.Message object at 0x1022a38d0>
    [2010-06-24 09:46:09,679: INFO/MainProcess] Task tasks.process_emails[154dcac0-3593-49a0-a7f5-2a5b4aa4f5c0] processed: None
  2. ask revised this gist Jun 24, 2010. 1 changed file with 22 additions and 22 deletions.
    44 changes: 22 additions & 22 deletions gistfile1.pyw
    Original file line number Diff line number Diff line change
    @@ -1,26 +1,26 @@
    if request.method == "POST":
    email_form = SendAnEmail(request.POST, prefix='emailform')
    if email_form.is_valid():
    connection = DjangoBrokerConnection()
    publisher = Publisher(connection=connection,
    exchange="sendemail",
    routing_key="sendemail_emails")
    publisher.send(email_form.cleaned_data.get('email_address'))
    publisher.close()
    connection.close()
    from carrot.connection import BrokerConnection
    from carrot.messaging import Consumer, Publisher


    then in my Celery Task:
    @task()
    def send_emails(n=10):
    conn = send_emails.establish_connection()
    pub = Publisher(conn, exchange="sendemail",
    routing_key="sendemail_emails")
    try:
    for i in xrange(n):
    pub.send({"e-mail": "[email protected]"})
    finally:
    pub.close()
    conn.close()


    try:
    connection = DjangoBrokerConnection()
    consumer = Consumer(connection=connection,
    queue="sendemail",
    exchange="sendemail",
    routing_key="sendemail_emails")

    logger.info("sending emails...")
    for message in consumer.iterqueue():
    logger.info("boo")
    logger.info(message.payload.get('email'))
    @task()
    def process_emails():
    conn = send_emails.establish_connection()
    consumer = Consumer(conn, queue="sendemail", exchange="sendemail",
    routing_key="sendemail_emails")
    for message in consumer.iterqueue():
    print("boo")
    print("Message: %s" % (message, ))
    message.ack()
  3. markhellewell renamed this gist Jun 24, 2010. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  4. markhellewell revised this gist Jun 24, 2010. 1 changed file with 22 additions and 0 deletions.
    22 changes: 22 additions & 0 deletions gistfile2.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    from carrot.connection import DjangoBrokerConnection
    from carrot.messaging import Publisher, Consumer
    connection = DjangoBrokerConnection()
    publisher = Publisher(connection=connection, exchange="sendemail", routing_key="sendemail_emails")
    publisher.send({'email': '[email protected]'})
    publisher.send({'email': '[email protected]'})
    publisher.send({'email': '[email protected]'})
    publisher.send({'email': '[email protected]'})
    publisher.send({'email': '[email protected]'})
    publisher.send({'email': '[email protected]'})
    publisher.send({'email': '[email protected]'})
    publisher.send({'email': '[email protected]'})
    publisher.send({'email': '[email protected]'})
    publisher.send({'email': '[email protected]'})
    publisher.send({'email': '[email protected]'})
    publisher.send({'email': '[email protected]'})
    publisher.send({'email': '[email protected]'})
    publisher.send({'email': '[email protected]'})
    publisher.send({'email': '[email protected]'})
    publisher.send({'email': '[email protected]'})
    publisher.close()
    connection.close()
  5. markhellewell revised this gist Jun 24, 2010. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions gistfile1.pyw
    Original file line number Diff line number Diff line change
    @@ -16,9 +16,9 @@ then in my Celery Task:
    try:
    connection = DjangoBrokerConnection()
    consumer = Consumer(connection=connection,
    queue="senddrop",
    exchange="senddrop",
    routing_key="senddrop_emails")
    queue="sendemail",
    exchange="sendemail",
    routing_key="sendemail_emails")

    logger.info("sending emails...")
    for message in consumer.iterqueue():
  6. markhellewell created this gist Jun 24, 2010.
    26 changes: 26 additions & 0 deletions gistfile1.pyw
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    if request.method == "POST":
    email_form = SendAnEmail(request.POST, prefix='emailform')
    if email_form.is_valid():
    connection = DjangoBrokerConnection()
    publisher = Publisher(connection=connection,
    exchange="sendemail",
    routing_key="sendemail_emails")
    publisher.send(email_form.cleaned_data.get('email_address'))
    publisher.close()
    connection.close()


    then in my Celery Task:


    try:
    connection = DjangoBrokerConnection()
    consumer = Consumer(connection=connection,
    queue="senddrop",
    exchange="senddrop",
    routing_key="senddrop_emails")

    logger.info("sending emails...")
    for message in consumer.iterqueue():
    logger.info("boo")
    logger.info(message.payload.get('email'))