Help

4

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

Avatar
Andreas Brueckl

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?

Avatar
Discard
6 Answers
7
Avatar
Vo Minh Thu
Best Answer

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).

1 Comment
Avatar
Discard
Avatar
ABC
-

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 .

5
Avatar
Vasiliy Birukov
Best Answer

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

Avatar
Discard
4
Avatar
Guewen Baconnier
Best Answer

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.

Avatar
Discard
1
Avatar
Viktor Nagy
Best Answer

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

Avatar
Discard
0
Avatar
Eugen Don
Best Answer

Hi my Friend, there is an app to start cron workers manually espacially for cases where users run their instances in wsgy mode.

You can also assign a automated action to the function of this module.


https://www.odoo.com/apps/modules/8.0/manual_cron/


Best Regards Eugen

Avatar
Discard
0
Avatar
Andreas Brueckl
Best Answer

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?

1 Comment
Avatar
Discard
Avatar
Daniel Reis
-

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