Skip to content
This repository has been archived by the owner on Nov 26, 2018. It is now read-only.

Example using Celery for plugin queue #147

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Example using Celery for plugin queue #147

wants to merge 1 commit into from

Conversation

ipmb
Copy link
Member

@ipmb ipmb commented Jun 25, 2015

Moving to a real queue will help us ensure we don't drop messages during restarts and can retry in the event of transient failures.

The bot would need to modify the message it puts in Redis to match what Celery expects. In Python, it would look like this:

import base64
import json
import uuid
import redis

r = redis.StrictRedis()

# this is the message it currently sends
arg = "{\"ChatBotId\":69,\"Raw\":\":[email protected] PRIVMSG #channel hello\",\"Received\":\"2015-06-25T04:01:51.964567066Z\",\"User\":\"user\",\"Host\":\"[email protected]\",\"Command\":\"PRIVMSG\",\"Args\":[\"#channel\"],\"Content\":\"hello\",\"IsCTCP\":false,\"Channel\":\"#channel\",\"BotNick\":\"[b__b]\"}\n"

msg = {
    'id': str(uuid.uuid4()),
    'task': 'botbot.apps.plugins.tasks.route_line',
    'args': [arg],
}

payload = {
    'body': base64.b64encode(json.dumps(msg)),
    'headers': {},
    'content-type': 'application/json',
    'content-encoding': 'utf-8', 
    'properties': {
        'body_encoding': 'base64',
        'correlation_id': msg['id'],
        'delivery_info': {
            'exchange': 'celery',
            'priority': 0,
            'routing_key': 'celery'
        },
        'delivery_mode': 2,
        'delivery_tag': str(uuid.uuid4()),
        'reply_to': str(uuid.uuid4()),
    }
}
r.lpush('celery', json.dumps(payload))

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant