diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..abf7486 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +*.pyc +build/ +.coverage +*.egg-info +dist/ diff --git a/django_pyres/__init__.py b/django_pyres/__init__.py new file mode 100644 index 0000000..3a0421b --- /dev/null +++ b/django_pyres/__init__.py @@ -0,0 +1,3 @@ +VERSION = (0, 1, 0) +__version__ = '.'.join(map(str, VERSION)) + diff --git a/django_pyres/conf.py b/django_pyres/conf.py new file mode 100644 index 0000000..1526ac7 --- /dev/null +++ b/django_pyres/conf.py @@ -0,0 +1,14 @@ +from django.conf import settings #noqa +from appconf import AppConf + +class PyresConf(AppConf): + HOST = "localhost:6379" + PASSWORD = None + WORKER_PIDFILE = None + WORKER_INTERVAL = None + WORKER_LOGFILE = None + WORKER_TIMEOUT= None + MANAGER_POOL_SIZE=2 + + class Meta: + prefix = 'pyres' diff --git a/django_pyres/core.py b/django_pyres/core.py new file mode 100644 index 0000000..ee72e9e --- /dev/null +++ b/django_pyres/core.py @@ -0,0 +1,4 @@ +from pyres import ResQ +from django.conf import settings +pyres = ResQ(getattr(settings,'PYRES_HOST','localhost:6379'),getattr(settings,'PYRES_PASSWORD',None)) + diff --git a/django_pyres/management/__init__.py b/django_pyres/management/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/django_pyres/management/commands/__init__.py b/django_pyres/management/commands/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/django_pyres/management/commands/pyres_manager.py b/django_pyres/management/commands/pyres_manager.py new file mode 100644 index 0000000..a9ad48b --- /dev/null +++ b/django_pyres/management/commands/pyres_manager.py @@ -0,0 +1,29 @@ +import logging +from django.core.management.base import BaseCommand, CommandError +from django_pyres.conf import settings + +from optparse import make_option +from pyres.horde import Khan +from pyres import setup_pidfile + +class Command(BaseCommand): + option_list = BaseCommand.option_list + ( + make_option("--pool", type="int", dest="pool_size", default=0, help="Number of minions to spawn under the manager."), + make_option('-l', '--log-level', dest='log_level', default='info', help='log level. Valid values are "debug", "info", "warning", "error", "critical", in decreasing order of verbosity. Defaults to "info" if parameter not specified.'), + make_option('-f', dest='logfile', help='If present, a logfile will be used. "stderr", "stdout", and "syslog" are all special values.'), + ) + help = 'Closes the specified poll for voting' + + def handle(self, queue_list, **options): + queues = queue_list.split(',') + log_level = getattr(logging, options['log_level'].upper(), 'INFO') + pool_size = options.get('pool_size') + if pool_size == 0: + pool_size = settings.PYRES_MANAGER_POOL_SIZE + setup_pidfile(settings.PYRES_WORKER_PIDFILE) + Khan.run( + pool_size=pool_size, + queues=queues, + server=settings.PYRES_HOST, + logging_level=log_level, + log_file=None) diff --git a/django_pyres/management/commands/pyres_worker.py b/django_pyres/management/commands/pyres_worker.py new file mode 100644 index 0000000..5368a58 --- /dev/null +++ b/django_pyres/management/commands/pyres_worker.py @@ -0,0 +1,27 @@ +import logging +from django.core.management.base import BaseCommand, CommandError +from django_pyres.conf import settings + +from optparse import make_option +from pyres.worker import Worker +from pyres import setup_logging, setup_pidfile + +class Command(BaseCommand): + option_list = BaseCommand.option_list + ( + make_option('-l', '--log-level', dest='log_level', default='info', help='log level. Valid values are "debug", "info", "warning", "error", "critical", in decreasing order of verbosity. Defaults to "info" if parameter not specified.'), + ) + help = 'Closes the specified poll for voting' + + def handle(self, queue_list, **options): + queues = queue_list.split(',') + log_level = getattr(logging, options['log_level'].upper(), 'INFO') + setup_logging(procname="pyres_worker", log_level=log_level, filename=None) + setup_pidfile(settings.PYRES_WORKER_PIDFILE) + Worker.run( + queues, + settings.PYRES_HOST, + settings.PYRES_WORKER_INTERVAL, + timeout=settings.PYRES_WORKER_TIMEOUT + ) + + diff --git a/django_pyres/models.py b/django_pyres/models.py new file mode 100644 index 0000000..ca200a0 --- /dev/null +++ b/django_pyres/models.py @@ -0,0 +1,2 @@ +from django.db import models +# Create your models here. diff --git a/django_pyres/views.py b/django_pyres/views.py new file mode 100644 index 0000000..60f00ef --- /dev/null +++ b/django_pyres/views.py @@ -0,0 +1 @@ +# Create your views here. diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..05d092b --- /dev/null +++ b/setup.py @@ -0,0 +1,25 @@ +from setuptools import setup, find_packages +version=__import__('django_pyres').__version__ +setup( + name='django_pyres', + version=version, + description='django pyres ', + author='Matt George', + author_email='mgeorge@gmail.com', + maintainer='Matt George', + license='MIT', + url='http://github.com/Pyres/django_pyres', + packages=find_packages(exclude=['ez_setup', 'example','testapp','tests']), + include_package_data=True, + install_requires=[ + 'pyres>=1.3', + ], + classifiers = [ + 'Development Status :: 4 - Beta', + 'Environment :: Console', + 'Intended Audience :: Developers', + 'License :: OSI Approved :: MIT License', + 'Operating System :: OS Independent', + 'Programming Language :: Python'], +) +