예제 #1
0
파일: run_huey.py 프로젝트: Psycojoker/huey
    def handle(self, *args, **options):
        config = load_config('huey.djhuey.conf.Configuration')

        if options['threads'] is not None:
            config.THREADS = options['threads']

        if options['periodic'] is not None:
            config.PERIODIC = options['periodic']

        self.autodiscover()

        queue = config.QUEUE
        result_store = config.RESULT_STORE
        task_store = config.TASK_STORE
        invoker = Invoker(queue, result_store, task_store)

        consumer = Consumer(invoker, config)
        consumer.run()
예제 #2
0
from huey.decorators import queue_command
from huey.exceptions import QueueException
from huey.queue import Invoker, QueueCommand, PeriodicQueueCommand
from huey.registry import registry
from huey.utils import local_to_utc
from huey.bin.config import BaseConfiguration
from huey.bin.huey_consumer import load_config, Consumer, IterableQueue

# store some global state
state = {}

# create a queue, result store and invoker for testing
test_queue = DummyQueue('test-queue')
test_result_store = DummyDataStore('test-queue')
test_task_store = DummyDataStore('test-tasks')
test_invoker = Invoker(test_queue, test_result_store, test_task_store)


# create a dummy config for passing to the consumer
class DummyConfiguration(BaseConfiguration):
    QUEUE = test_queue
    RESULT_STORE = test_result_store
    TASK_STORE = test_result_store
    THREADS = 2


@queue_command(test_invoker)
def modify_state(k, v):
    state[k] = v
    return v
예제 #3
0
파일: config.py 프로젝트: Psycojoker/huey
from huey.backends.redis_backend import RedisBlockingQueue, RedisDataStore
from huey.bin.config import BaseConfiguration
from huey.queue import Invoker

queue = RedisBlockingQueue('test-queue', host='localhost', port=6379)
result_store = RedisDataStore('results', host='localhost', port=6379)

invoker = Invoker(queue, result_store=result_store)


class Configuration(BaseConfiguration):
    QUEUE = queue
    RESULT_STORE = result_store
    PERIODIC = True
예제 #4
0
파일: __init__.py 프로젝트: Psycojoker/huey
    backup_name = settings.DATABASES['default']['NAME'].rsplit('/', 1)[-1]
else:
    backup_name = 'huey'

if isinstance(queue, basestring):
    QueueClass = load_class(queue)
    queue = QueueClass(config.get('QUEUE_NAME', backup_name),
                       **config.get('QUEUE_CONNECTION', {}))
    config['QUEUE'] = queue

result_store = config.get('RESULT_STORE', None)

if isinstance(result_store, basestring):
    DataStoreClass = load_class(result_store)
    result_store = DataStoreClass(config.get('RESULT_STORE_NAME', backup_name),
                                  **config.get('RESULT_STORE_CONNECTION', {}))
    config['RESULT_STORE'] = result_store

task_store = config.get('TASK_STORE', None)

if isinstance(task_store, basestring):
    DataStoreClass = load_class(task_store)
    task_store = DataStoreClass(config.get('TASK_STORE_NAME', backup_name),
                                **config.get('TASK_STORE_CONNECTION', {}))
    config['TASK_STORE'] = task_store

invoker = Invoker(queue,
                  result_store,
                  task_store,
                  always_eager=config.get('ALWAYS_EAGER', False))
예제 #5
0
import datetime
import unittest

from huey.backends.dummy import DummyQueue, DummyDataStore
from huey.decorators import queue_command, periodic_command, crontab
from huey.exceptions import QueueException
from huey.queue import Invoker, QueueCommand, PeriodicQueueCommand, CommandSchedule
from huey.registry import registry
from huey.utils import EmptyData, local_to_utc

queue_name = 'test-queue'
queue = DummyQueue(queue_name)
invoker = Invoker(queue)

res_queue_name = 'test-queue-2'
res_queue = DummyQueue(res_queue_name)
res_store = DummyDataStore(res_queue_name)
task_store = DummyDataStore(res_queue_name)

res_invoker = Invoker(res_queue, res_store, task_store)
res_invoker_nones = Invoker(res_queue, res_store, task_store, store_none=True)

# store some global state
state = {}


# create a decorated queue command
@queue_command(invoker)
def add(key, value):
    state[key] = value
예제 #6
0
        __import__(config_module)
        mod = sys.modules[config_module]
    except ImportError:
        err('Unable to import "%s"' % config_module)

    try:
        config = getattr(mod, config_obj)
    except AttributeError:
        err('Missing module-level "%s"' % config_obj)

    return config


if __name__ == '__main__':
    args = sys.argv[1:]

    if len(args) == 0:
        parser.print_help()
        err('Error, missing required parameter config.module')
        sys.exit(1)

    config = load_config(args[0])

    queue = config.QUEUE
    result_store = config.RESULT_STORE
    task_store = config.TASK_STORE
    invoker = Invoker(queue, result_store, task_store)

    consumer = Consumer(invoker, config)
    consumer.run()