Example #1
0
# -*- coding: utf-8 -*-
"""
    !!! NOT READY FOR PRODUCTION !!!
"""
import logging
from taskmq import Consumer
from time import sleep

# Declare the consumer.
consumer = Consumer(host='some.host.tld', user='******', password='', vhost='/')

# Declare a direct exchange.
base_exchange = consumer.exchange('base_exchange')

# Declare two queues.
queue_1 = consumer.queue('queue_1')
queue_2 = consumer.queue('queue_2')


def a_basic_task():
    sleep(10)
    return 'HEY'

queue_1.register(a_basic_task)

if __name__ == '__main__':

    logging.basicConfig(level=logging.DEBUG)

    try:
        consumer.start()
Example #2
0
# -*- coding: utf-8 -*-
import logging
from taskmq import Consumer
from . import config

logging.basicConfig(level=logging.DEBUG)


def a_plus_b(a, b):
    if not isinstance(a, int) or not isinstance(b, int):
        raise TypeError('Except an int type')
    return a + b


consumer = Consumer(host=config.BROKER_HOST,
                    port=config.BROKER_PORT,
                    user=config.BROKER_USER,
                    password=config.BROKER_PASSWORD,
                    vhost=config.BROKER_VHOST)

print '...Create queue'
queue1 = consumer.queue('tests')
queue1.queue.purge()
print queue1

print '...Add task to the queue'
queue1.task(a_plus_b)
print queue1

consumer.start()
Example #3
0
# -*- coding: utf-8 -*-
"""
    !!! NOT READY FOR PRODUCTION !!!
"""
import logging
from taskmq import Consumer
from time import sleep

# Declare the consumer.
consumer = Consumer(host='some.host.tld', user='******', password='', vhost='/')

# Declare a direct exchange.
base_exchange = consumer.exchange('base_exchange')

# Declare two queues.
queue_1 = consumer.queue('queue_1')
queue_2 = consumer.queue('queue_2')


def a_basic_task():
    sleep(10)
    return 'HEY'


queue_1.register(a_basic_task)

if __name__ == '__main__':

    logging.basicConfig(level=logging.DEBUG)

    try:
Example #4
0
from . import config


logging.basicConfig(level=logging.DEBUG)


def a_plus_b(a, b):
    if not isinstance(a, int) or not isinstance(b, int):
        raise TypeError('Except an int type')
    return a + b


consumer = Consumer(
    host=config.BROKER_HOST,
    port=config.BROKER_PORT,
    user=config.BROKER_USER,
    password=config.BROKER_PASSWORD,
    vhost=config.BROKER_VHOST
)

print '...Create queue'
queue1 = consumer.queue('tests')
queue1.queue.purge()
print queue1

print '...Add task to the queue'
queue1.task(a_plus_b)
print queue1

consumer.start()