zhebrak / django-statsy

Statistics for your Django project
MIT License
63 stars 9 forks source link

Using uWSGI's spooler or rq instead of Celery #39

Open MechanisM opened 7 years ago

MechanisM commented 7 years ago

Hello! I would like to use uWSGI spooler for async tasks. It can be almost the same as tasks.py:


from django_uwsgi.decorators import spool
from statsy.models import StatsyObject

@spool
def send(**kwargs):
    obj = StatsyObject.create(**kwargs)

    return obj.serialize()

@spool
def send_callback(result, callback_path):
    module, callback = callback_path.rsplit('.', 1)
    module = importlib.import_module(module)
    callback = getattr(module, callback)

    return callback(result)

but file name can be smth like spooler.py or smth like that. and then in uwsgi.ini:

spooler = spooler
spooler-import = statsy.spooler

just needed some workaround to switch between celery and spooler(or even rq can be added) in core.py:

send_task.spool(kwargs=self._clean_kwargs_async(kwargs), link=callback)

personally I prefer not to use celery when there's not so lots of tasks, and since I deploy ьн project via uwsgi, I can use uwsgi's spooler and don't need to install and setup huge celery.

zhebrak commented 7 years ago

Hi! Good idea in case you are not using celery in your project and want to keep your stack as minimal as possible.