如何在celery 中创建多个先进先出队列?

ubof19bj  于 2021-06-08  发布在  Redis
关注(0)|答案(0)|浏览(253)

我在一台机器上运行了一个django web服务,它向另一台机器上运行的celery 工人提交作业。
这是我的想法 models.py 看起来像:

class Department(models.Model):
    name = models.CharField(max_length=200)

class Employee(models.Model):
    name = models.CharField(max_length=200)
    department = models.ForeignKey(Department)

我的celery systemd服务文件如下所示:

[Unit]
Description=celery daemon
After=network.target

[Service]
Type=forking
User=<user>
Group=<group>
WorkingDirectory=<path_to_working_directory>

ExecStart=celery multi start worker -A project --pidfile=<process_id_path> \
--concurrency=1 --logfile=<path_to_logfile> --loglevel=debug
ExecStop=celery multi stopwait worker -A project --pidfile=<process_id_path> \
--concurrency=1 --logfile=<path_to_logfile> --loglevel=debug
ExecReload=celery multi refresh worker -A project --pidfile=<process_id_path> \
--concurrency=1 --logfile=<path_to_logfile> --loglevel=debug

[Install]
WantedBy=multi-user.target

目前,我使用django信号,它在每次添加新部门时创建一个新队列。但是,如果在systemd文件中将并发性设置为1,那么worker一次只运行一个作业。如果我没有提到并发性,那么它有时会从同一队列并行运行多个作业。我希望它并行运行多个作业,但在给定的时间内,每个队列中只能运行一个作业。
例如。假设有3个部门a,b,c。这将创建3个队列,每个部门一个,分别为queuea、queueb和queuec。我希望worker同时运行queuea中的一个作业、queueb中的一个作业和qukec中的一个作业。但它决不能同时从一个队列中运行多个作业。
我怎样用celery 达到这个目的?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题