Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

4

What's the right way to start cron worker jobs?

By
Andreas Brueckl
on 2/12/13, 9:57 AM 15,013 views

I have setup a multi-threaded environment with nginx and gunicorn. But since gunicorn does not run openerp-cron-workers, I need to start dedicated cron-workers.

As far as I understand I have to run the "oe cron" command. But for this command there are only two options available: "--addons" and "--database". When I call this command I get an exception because the PostgreSQL port is not correct.

So how can I specify configuration options (or a config file) for the "oe" command? What is the correct way to run cron-worker jobs in a productive environment?

I run gunicorn with the following command: "gunicorn openerp:wsgi.wsgi_server.application -c ../gunicorn.conf.py"

Here is my guniconf.conf.py file:

import openerp 
import multiprocessing 
bind = '0.0.0.0:8000' 
pidfile = '.gunicorn.pid'   
conf = openerp.tools.config

conf['addons_path'] =  "openerp/addons,../addons,../web/addons,../custom-addons"
conf['db_host'] = False 
conf['db_port'] = 5433 
conf['db_user'] = 'user1' 
conf['db_password'] = 'xx' 
conf['dbfilter'] = 'test.*'

conf['logfile'] = '/var/log/openerp-server-7.log'

workers = multiprocessing.cpu_count() * 2 + 1

When I look into the source in method "application" of wsgi_server.py I cannot see where the cron jobs will be started. There are only 2 files which handle "max_cron_threads": "server/openerp/service/workers.py" and "server/openerp/service/cron.py". Both of them are not called in gunicorn-mode.

Maybe I misunderstand something. How to I correctly run openerp in multiprocess-mode?

7
Vo Minh Thu
On 2/12/13, 5:24 PM

In 6.1, there is an additional script called openerp-cron-worker to run a process dedicated to cron jobs.

In 7.0, the recommended way is to use the integrated multi-processing support (i.e. not Gunicorn although it should work). The option --workers sets how many HTTP workers are started, while the option --max-cron-threads sets how many cron workers are started. That option is misleading: both HTTP and cron workers, when using --workers, are real processes. If you still want to use Gunicorn, you may want to try --workers 0 and --max-cron-threads 1 to have a dedicated cron process.

Your question is tagged as 7.0 but refers to the oe script which has been recently added in trunk. If its features are too limited (which seems the case with what you say) or bugged, please create a bug report on launchpad. Otherwise this should be the right way to start cron workers in the future (independently of the integrated multi-process support with the --workers option).

Is it possible when defining conf['workers'] = '0' and conf['max_cron_threads'] = '1' in gunicorn.conf.py ? . I've tried that but it didnt worked .

ABC
on 5/3/13, 4:57 AM
5

Vasiliy Birukov

--Vasiliy Birukov--
3446
| 6 6 8
Russian Federation
--Vasiliy Birukov--

Help develop and implement any project on base Odoo.

Vasiliy Birukov
On 12/5/14, 9:07 AM

Try our module cron for manual start cron from odoo interface.

4

Guewen Baconnier - Software Developer, Camptocamp

--Guewen Baconnier - Software Developer, Camptocamp--
2658
| 6 7 8
Lausanne, Switzerland
--Guewen Baconnier - Software Developer, Camptocamp--

Guewen works at Camptocamp as an Odoo developer since 2010. He is the lead developer of the Odoo Connector framework and the Magento Connector. He is a delegate member of the OCA, a committer and an active contributor to the OCA projects.

 

Guewen Baconnier - Software Developer, Camptocamp
On 2/12/13, 10:19 AM

Since version 7.0, the cron workers are launched automatically when you start openerp in multi-process mode.

It spawn n HTTP workers where n is a number in the configuration key workers, and it spawn m Cron workers where m is a number in the configuration key max_cron_threads.

1
Viktor Nagy
On 10/11/14, 10:43 AM

I just run into this same problem running an instance with uwsgi (not gunicorn). The instance was running fine for more than a month, but no cron jobs were running.
The reason behind this unexpected behavior was pretty simple. The cron jobs are never started running only a simple wsgi application.

I've followed the code base as much as I could, and the only places where cron jobs are started are when openerp is started from the command line. Thus cron is never started for wsgi apps.
For this reason, you have 2 possibilities:

  1. run a separate openerp-server instance that is initialised, and will only consume your cron job
  2. add the cron init code to your wsgi initialisation

I've tried the latter. My current setup seems to work well, but I'm not sure if it's really OK or not. Here follows what I did:

  1. Add an `import cron` line towards the top of openerp/service/wsgi_server.py.
  2. Add `cron.start_service()` around line 413, after the `openerp.service.start_internal()` call.
  3. Restart your server

--------------

NB: finally my solution is to drop gunicorn from the stack, and use the openerp-server command with workers and max-cron-threads set as suggested above

0

Andreas Brueckl

--Andreas Brueckl--
5056
| 7 8 7
Vienna, Austria
--Andreas Brueckl--
OpenERP Consulting and Development
Andreas Brueckl
On 2/12/13, 10:39 AM

Thank you for the answer.

I run gunicorn with the following command: "gunicorn openerp:wsgi.wsgi_server.application -c ../gunicorn.conf.py"

Here is my guniconf.conf.py file:

import openerp 
import multiprocessing 
bind = '0.0.0.0:8000' 
pidfile = '.gunicorn.pid'   
conf = openerp.tools.config

conf['addons_path'] =  "openerp/addons,../addons,../web/addons,../custom-addons"
conf['db_host'] = False 
conf['db_port'] = 5433 
conf['db_user'] = 'user1' 
conf['db_password'] = 'xx' 
conf['dbfilter'] = 'test.*'

conf['logfile'] = '/var/log/openerp-server-7.log'

workers = multiprocessing.cpu_count() * 2 + 1

When I look into the source in method "application" of wsgi_server.py I cannot see where the cron jobs will be started. There are only 2 files which handle "max_cron_threads": "server/openerp/service/workers.py" and "server/openerp/service/cron.py". Both of them are not called in gunicorn-mode.

Maybe I misunderstand something. How to I correctly run openerp in multiprocess-mode?

Andreas, to add more details to your question you should edit it expanding the additional details, instead of posting them as an "answer".

Daniel Reis
on 2/12/13, 11:01 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

2 follower(s)

Stats

Asked: 2/12/13, 9:57 AM
Seen: 15013 times
Last updated: 5/20/16, 10:59 PM