Giter VIP home page Giter VIP logo

task_queue's Introduction

task_queue

Odoo async task module with celery

安装

  • pip install celery==4.1.0
  • pip install sqlalchemy (如果需要存储任务执行结果的话)
  • pip install redis (如果使用redis作为消息存储后端)

配置

在 odoo 的 conf 配置文件中可用的配置项:

# 消息存储后端
celery_broker_url = redis://localhost

# 是否存储任务执行结果
celery_result_backend_db = postgresql://openerp:openerp@localhost/srm_sunwoda_180108

# 默认的队列
celery_default_queue = odoo

# 可选队列
celery_queues = queue1, queue2, queue3

使用

from odoo.addons.task_queue.api import Async

@Aysnc()
@api.model
def func(self, a, b):
    pass


@Aysnc(queue='queue1')
@api.multi
def func1(self, a, b):
    pass


@Aysnc(queue='queue2')
@api.one
def func2(self, a, b):
    pass

注意:确保方法的参数均为可序列化的python内置类型

在调用前如果异步任务执行时会引用到刚变动的记录请执行下数据库 commit 使变动确实生效

多进程worker同时跑时可能会出现odoo的事务错误,建议odoo中多使用autocommit=True的模式操作数据库

Worker的运行

参考如下task_worker.py 代码:

# coding=utf-8

__import__('pkg_resources').declare_namespace('odoo.addons')


import odoo
from odoo.cli.shell import Shell


args = ['-c', 'xxx.conf']
Shell().init(args)

from odoo.addons.task_queue.tasks import *

启动: celery -A task_worker worker --loglevel=info

task_queue's People

Contributors

jonexiong avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.