odoo10 集成 celery

先安装了一个celery模块,自动装上了celery,redis,下次试试不装这个模块。
模块地址:https://apps.odoo.com/apps/modules/10.0/celery/
之后运行的时候报错:AttributeError("‘str’ object has no attribute ‘iteritems’",)。降低了一下redis包的版本到2.10.6之后可以了。

安装包celery,redis,celery-with-redis(这个也许不需要)
pip install celery==3.1.26.post2 -i https://pypi.tuna.tsinghua.edu.cn/simple some-package
包后加入“==”指定版本号
后面添加清华源

安装redis
https://editor.csdn.net/md/?articleId=112172749

添加一个odoo.py文件

import time
from celery import Celery

app = Celery('odoo.addons.celery', broker='redis://localhost:6379/0')

@app.task(name='odoo.addons.celery.odoo.just_try')
def just_try(a,b):
    time.sleep(30)
    print(a+b)
#装饰器不传name的话报了just_try未注册的bug

另一个文件中引用这个方法,导入该方法时必须是绝对路径

from odoo.addons.celery.odoo import just_try

def test(self):
    for i in range(0,20):
        pid = just_try.delay(1,2)
        print(pid)

启动redis
再启动一个终端运行celery:

celery -A odoo worker --loglevel=info
#odoo 是文件名,需要在celery模块下执行

之后调用test方法,就可以在celery里看到任务的执行了

查看celery任务状态
参考:https://www.cnblogs.com/shanchuan/p/12818117.html

直接登录redis

# redis-cli
127.0.0.1:6379> llen celery
(integer) 0

默认键为celery,现在长度为0,即没有未处理的任务

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值