Skip to content

Commit

Permalink
manual merge of multicorn
Browse files Browse the repository at this point in the history
  • Loading branch information
antonylesuisse committed Sep 22, 2012
1 parent f4a296e commit 4679680
Show file tree
Hide file tree
Showing 14 changed files with 619 additions and 333 deletions.
63 changes: 0 additions & 63 deletions gunicorn.conf.py

This file was deleted.

26 changes: 10 additions & 16 deletions openerp-server
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ def run_test_file(dbname, test_file):
except Exception:
_logger.exception('Failed to initialize database `%s` and run test file `%s`.', dbname, test_file)


def export_translation():
config = openerp.tools.config
dbname = config['db_name']
Expand Down Expand Up @@ -205,6 +204,7 @@ def quit_on_signals():
except KeyboardInterrupt:
pass

config = openerp.tools.config
if config['pidfile']:
os.unlink(config['pidfile'])

Expand All @@ -217,8 +217,7 @@ def configure_babel_localedata_path():
import babel
babel.localedata._dirname = os.path.join(os.path.dirname(sys.executable), 'localedata')

if __name__ == "__main__":

def main():
os.environ["TZ"] = "UTC"

check_root_user()
Expand Down Expand Up @@ -247,20 +246,13 @@ if __name__ == "__main__":
sys.exit(0)

if not config["stop_after_init"]:
setup_pid_file()
# Some module register themselves when they are loaded so we need the
# services to be running before loading any registry.
openerp.service.start_services()

for m in openerp.conf.server_wide_modules:
try:
openerp.modules.module.load_openerp_module(m)
except Exception:
msg = ''
if m == 'web':
msg = """
The `web` module is provided by the addons found in the `openerp-web` project.
Maybe you forgot to add those addons in your addons_path configuration."""
_logger.exception('Failed to load server-wide module `%s`.%s', m, msg)
if config['workers']:
openerp.service.start_services_workers()
else:
openerp.service.start_services()

if config['db_name']:
for dbname in config['db_name'].split(','):
Expand All @@ -269,8 +261,10 @@ Maybe you forgot to add those addons in your addons_path configuration."""
if config["stop_after_init"]:
sys.exit(0)

setup_pid_file()
_logger.info('OpenERP server is running, waiting for connections...')
quit_on_signals()

if __name__ == "__main__":
main()

# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
53 changes: 53 additions & 0 deletions openerp-wsgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/python
# WSGI Handler sample configuration file.
#
# Change the appropriate settings below, in order to provide the parameters
# that would normally be passed in the command-line.
# (at least conf['addons_path'])
#
# For generic wsgi handlers a global application is defined.
# For uwsgi this should work:
# $ uwsgi --http :9090 --pythonpath . --wsgi-file openerp-wsgi.py
#
# For gunicorn additional globals need to be defined in the Gunicorn section.
# Then the following command should run:
# $ gunicorn openerp:wsgi.core.application -c gunicorn.conf.py

import openerp

#----------------------------------------------------------
# Common
#----------------------------------------------------------
# Equivalent of --load command-line option
openerp.conf.server_wide_modules = ['web']
conf = openerp.tools.config

# Path to the OpenERP Addons repository (comma-separated for
# multiple locations)
conf['addons_path'] = '/home/openerp/addons/trunk,/home/openerp/web/trunk/addons'
conf['addons_path'] = '/home/wis/stuff/version/openerp/source/addons/6.1,/home/wis/stuff/version/openerp/source/web/6.1/addons'


# Optional database config if not using local socket
#conf['db_name'] = 'mycompany'
#conf['db_host'] = 'localhost'
#conf['db_user'] = 'foo'
#conf['db_port'] = 5432
#conf['db_password'] = 'secret'

#----------------------------------------------------------
# Generic WSGI handlers application
#----------------------------------------------------------
application = openerp.service.wsgi_server.application

#----------------------------------------------------------
# Gunicorn
#----------------------------------------------------------
# Standard OpenERP XML-RPC port is 8069
bind = '127.0.0.1:8069'
pidfile = '.gunicorn.pid'
workers = 4
timeout = 240
max_requests = 2000

# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
12 changes: 10 additions & 2 deletions openerp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,19 @@
import service
import sql_db
import test
import tiny_socket
import tools
import wizard
import workflow
import wsgi
# backward compatilbility
# TODO: This is for the web addons, can be removed later.
wsgi = service
wsgi.register_wsgi_handler = wsgi.wsgi_server.register_wsgi_handler
# Is the server running in multi-process mode (e.g. behind Gunicorn).
# If this is True, the processes have to communicate some events,
# e.g. database update or cache invalidation. Each process has also
# its own copy of the data structure and we don't need to care about
# locks between threads.
multi_process = True

# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

99 changes: 99 additions & 0 deletions openerp/addons/base/ir/ir_cron.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,105 @@ def _run_jobs_multithread(self):
cr.commit()
cr.close()

def _process_job(self, cr, job):
""" Run a given job taking care of the repetition.
The cursor has a lock on the job (aquired by _acquire_job()).
:param job: job to be run (as a dictionary).
"""
try:
now = datetime.now()
nextcall = datetime.strptime(job['nextcall'], DEFAULT_SERVER_DATETIME_FORMAT)
numbercall = job['numbercall']

ok = False
while nextcall < now and numbercall:
if numbercall > 0:
numbercall -= 1
if not ok or job['doall']:
self._callback(cr, job['user_id'], job['model'], job['function'], job['args'], job['id'])
if numbercall:
nextcall += _intervalTypes[job['interval_type']](job['interval_number'])
ok = True
addsql = ''
if not numbercall:
addsql = ', active=False'
cr.execute("UPDATE ir_cron SET nextcall=%s, numbercall=%s"+addsql+" WHERE id=%s",
(nextcall.strftime(DEFAULT_SERVER_DATETIME_FORMAT), numbercall, job['id']))

finally:
cr.commit()
cr.close()

@classmethod
def _acquire_job(cls, db_name):
# TODO remove 'check' argument from addons/base_action_rule/base_action_rule.py
""" Try to process one cron job.
This selects in database all the jobs that should be processed. It then
tries to lock each of them and, if it succeeds, run the cron job (if it
doesn't succeed, it means the job was already locked to be taken care
of by another thread) and return.
If a job was processed, returns True, otherwise returns False.
"""
db = openerp.sql_db.db_connect(db_name)
cr = db.cursor()
try:
# Careful to compare timestamps with 'UTC' - everything is UTC as of v6.1.
cr.execute("""SELECT * FROM ir_cron
WHERE numbercall != 0
AND active AND nextcall <= (now() at time zone 'UTC')
ORDER BY priority""")
for job in cr.dictfetchall():
task_cr = db.cursor()
try:
# Try to grab an exclusive lock on the job row from within the task transaction
acquired_lock = False
task_cr.execute("""SELECT *
FROM ir_cron
WHERE id=%s
FOR UPDATE NOWAIT""",
(job['id'],), log_exceptions=False)
acquired_lock = True
except psycopg2.OperationalError, e:
if e.pgcode == '55P03':
# Class 55: Object not in prerequisite state; 55P03: lock_not_available
_logger.debug('Another process/thread is already busy executing job `%s`, skipping it.', job['name'])
continue
else:
# Unexpected OperationalError
raise
finally:
if not acquired_lock:
# we're exiting due to an exception while acquiring the lot
task_cr.close()

# Got the lock on the job row, run its code
_logger.debug('Starting job `%s`.', job['name'])
openerp.modules.registry.RegistryManager.check_registry_signaling(db_name)
registry = openerp.pooler.get_pool(db_name)
registry[cls._name]._process_job(task_cr, job)
openerp.modules.registry.RegistryManager.signal_caches_change(db_name)
return True

except psycopg2.ProgrammingError, e:
if e.pgcode == '42P01':
# Class 42 — Syntax Error or Access Rule Violation; 42P01: undefined_table
# The table ir_cron does not exist; this is probably not an OpenERP database.
_logger.warning('Tried to poll an undefined table on database %s.', db_name)
else:
raise
except Exception, ex:
_logger.warning('Exception in cron:', exc_info=True)

finally:
cr.commit()
cr.close()

return False

def update_running_cron(self, cr):
""" Schedule as soon as possible a wake-up for this database. """
# Verify whether the server is already started and thus whether we need to commit
Expand Down
30 changes: 0 additions & 30 deletions openerp/db/__init__.py

This file was deleted.

Loading

0 comments on commit 4679680

Please sign in to comment.