美文网首页
celery python

celery python

作者: hehehehe | 来源:发表于2023-10-11 18:06 被阅读0次
    proj/__init__.py
        /celery.py
        /tasks.py
    

    proj/celery.py

    from celery import Celery
    
    backend = 'redis://127.0.0.1:6379/1'
    broker = 'redis://127.0.0.1:6379/2'
    
    app = Celery('proj',
                 broker=broker,
                 backend=backend,
                 include=['proj.task_poi',
                          'proj.task_hn'])
    
    # Optional configuration, see the application user guide.
    app.conf.update(
        result_expires=3600,
    )
    
    if __name__ == '__main__':
        app.start()
    
    

    proj/tasks.py

    from .celery import app
    
    
    @app.task
    def add(x, y):
        return x + y
    
    
    @app.task
    def mul(x, y):
        return x * y
    
    
    @app.task
    def xsum(numbers):
        return sum(numbers)
    
    
    $ celery -A proj worker -l info
    

    相关文章

      网友评论

          本文标题:celery python

          本文链接:https://www.haomeiwen.com/subject/zvqnbdtx.html