Stefan Rijnhart
11 years ago
7 changed files with 208 additions and 0 deletions
-
1cron_run_manually/__init__.py
-
36cron_run_manually/__openerp__.py
-
39cron_run_manually/i18n/cron_run_manually.pot
-
38cron_run_manually/i18n/nl.po
-
1cron_run_manually/model/__init__.py
-
73cron_run_manually/model/ir_cron.py
-
20cron_run_manually/view/ir_cron.xml
@ -0,0 +1 @@ |
|||||
|
import model |
@ -0,0 +1,36 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################## |
||||
|
# |
||||
|
# OpenERP, Open Source Management Solution |
||||
|
# This module copyright (C) 2013 Therp BV (<http://therp.nl>) |
||||
|
# Code snippets from openobject-server copyright (C) 2004-2013 OpenERP S.A. |
||||
|
# |
||||
|
# This program is free software: you can redistribute it and/or modify |
||||
|
# it under the terms of the GNU Affero General Public License as |
||||
|
# published by the Free Software Foundation, either version 3 of the |
||||
|
# License, or (at your option) any later version. |
||||
|
# |
||||
|
# This program is distributed in the hope that it will be useful, |
||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
# GNU Affero General Public License for more details. |
||||
|
# |
||||
|
# You should have received a copy of the GNU Affero General Public License |
||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
############################################################################## |
||||
|
|
||||
|
{ |
||||
|
'name': 'Call cron jobs from their form view', |
||||
|
'version': '0.1', |
||||
|
'author': ["Therp BV", "OpenERP S.A."], |
||||
|
'license': 'AGPL-3', |
||||
|
'category': 'Tools', |
||||
|
'description': """ |
||||
|
This module adds a button to the cron scheduled task form in OpenERP |
||||
|
that allows the administrator to run the job immediately, independently |
||||
|
of the scheduler. |
||||
|
""", |
||||
|
'depends': ['base'], |
||||
|
'data': ['view/ir_cron.xml'], |
||||
|
} |
@ -0,0 +1,39 @@ |
|||||
|
# Translation of OpenERP Server. |
||||
|
# This file contains the translation of the following modules: |
||||
|
# * cron_run_manually |
||||
|
# |
||||
|
msgid "" |
||||
|
msgstr "" |
||||
|
"Project-Id-Version: OpenERP Server 7.0\n" |
||||
|
"Report-Msgid-Bugs-To: \n" |
||||
|
"POT-Creation-Date: 2013-08-12 18:26+0000\n" |
||||
|
"PO-Revision-Date: 2013-08-12 18:26+0000\n" |
||||
|
"Last-Translator: <>\n" |
||||
|
"Language-Team: \n" |
||||
|
"MIME-Version: 1.0\n" |
||||
|
"Content-Type: text/plain; charset=UTF-8\n" |
||||
|
"Content-Transfer-Encoding: \n" |
||||
|
"Plural-Forms: \n" |
||||
|
|
||||
|
#. module: cron_run_manually |
||||
|
#: code:addons/cron_run_manually/model/ir_cron.py:71 |
||||
|
#, python-format |
||||
|
msgid "Another process/thread is already busy executing this job" |
||||
|
msgstr "Another process/thread is already busy executing this job" |
||||
|
|
||||
|
#. module: cron_run_manually |
||||
|
#: view:ir.cron:0 |
||||
|
msgid "Run now" |
||||
|
msgstr "Run now" |
||||
|
|
||||
|
#. module: cron_run_manually |
||||
|
#: model:ir.model,name:cron_run_manually.model_ir_cron |
||||
|
msgid "ir.cron" |
||||
|
msgstr "ir.cron" |
||||
|
|
||||
|
#. module: cron_run_manually |
||||
|
#: code:addons/cron_run_manually/model/ir_cron.py:70 |
||||
|
#, python-format |
||||
|
msgid "Error" |
||||
|
msgstr "Error" |
||||
|
|
@ -0,0 +1,38 @@ |
|||||
|
# Translation of OpenERP Server. |
||||
|
# This file contains the translation of the following modules: |
||||
|
# * cron_run_manually |
||||
|
# |
||||
|
msgid "" |
||||
|
msgstr "" |
||||
|
"Project-Id-Version: OpenERP Server 7.0\n" |
||||
|
"Report-Msgid-Bugs-To: \n" |
||||
|
"POT-Creation-Date: 2013-08-12 18:26+0000\n" |
||||
|
"PO-Revision-Date: 2013-08-12 18:26+0000\n" |
||||
|
"Last-Translator: <>\n" |
||||
|
"Language-Team: \n" |
||||
|
"MIME-Version: 1.0\n" |
||||
|
"Content-Type: text/plain; charset=UTF-8\n" |
||||
|
"Content-Transfer-Encoding: \n" |
||||
|
"Plural-Forms: \n" |
||||
|
|
||||
|
#. module: cron_run_manually |
||||
|
#: code:addons/cron_run_manually/model/ir_cron.py:71 |
||||
|
#, python-format |
||||
|
msgid "Another process/thread is already busy executing this job" |
||||
|
msgstr "Deze job wordt op dit moment al uitgevoerd door een ander proces" |
||||
|
|
||||
|
#. module: cron_run_manually |
||||
|
#: view:ir.cron:0 |
||||
|
msgid "Run now" |
||||
|
msgstr "Nu uitvoeren" |
||||
|
|
||||
|
#. module: cron_run_manually |
||||
|
#: model:ir.model,name:cron_run_manually.model_ir_cron |
||||
|
msgid "ir.cron" |
||||
|
msgstr "ir.cron" |
||||
|
|
||||
|
#. module: cron_run_manually |
||||
|
#: code:addons/cron_run_manually/model/ir_cron.py:70 |
||||
|
#, python-format |
||||
|
msgid "Error" |
||||
|
msgstr "Fout" |
@ -0,0 +1 @@ |
|||||
|
import ir_cron |
@ -0,0 +1,73 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################## |
||||
|
# |
||||
|
# OpenERP, Open Source Management Solution |
||||
|
# This module copyright (C) 2013 Therp BV (<http://therp.nl>) |
||||
|
# Code snippets from openobject-server copyright (C) 2004-2013 OpenERP S.A. |
||||
|
# |
||||
|
# This program is free software: you can redistribute it and/or modify |
||||
|
# it under the terms of the GNU Affero General Public License as |
||||
|
# published by the Free Software Foundation, either version 3 of the |
||||
|
# License, or (at your option) any later version. |
||||
|
# |
||||
|
# This program is distributed in the hope that it will be useful, |
||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
# GNU Affero General Public License for more details. |
||||
|
# |
||||
|
# You should have received a copy of the GNU Affero General Public License |
||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
############################################################################## |
||||
|
|
||||
|
import psycopg2 |
||||
|
import logging |
||||
|
from openerp.osv import orm |
||||
|
from openerp.tools.translate import _ |
||||
|
from openerp.tools.safe_eval import safe_eval |
||||
|
|
||||
|
class irCron(orm.Model): |
||||
|
_inherit = 'ir.cron' |
||||
|
|
||||
|
def run_manually(self, cr, uid, ids, context=None): |
||||
|
""" |
||||
|
Run a job from the cron form view. |
||||
|
|
||||
|
Cut and paste of code snippets from addons/base/ir/ir_cron.py |
||||
|
""" |
||||
|
logger = logging.getLogger('cron_run_manually') |
||||
|
cr.execute( |
||||
|
""" |
||||
|
SELECT * from ir_cron |
||||
|
WHERE id in %s |
||||
|
""", (tuple(ids),)) |
||||
|
jobs = cr.dictfetchall() |
||||
|
|
||||
|
for job in jobs: |
||||
|
try: |
||||
|
# Try to grab an exclusive lock on the job row |
||||
|
# until the end of the transaction |
||||
|
cr.execute( |
||||
|
"""SELECT * |
||||
|
FROM ir_cron |
||||
|
WHERE id=%s |
||||
|
FOR UPDATE NOWAIT""", |
||||
|
(job['id'],), log_exceptions=False) |
||||
|
|
||||
|
# Got the lock on the job row, run its code |
||||
|
logger.debug('Job `%s` triggered from form', job['name']) |
||||
|
model = self.pool.get(job['model']) |
||||
|
method = getattr(model, job['function']) |
||||
|
args = safe_eval('tuple(%s)' % (job['args'] or '')) |
||||
|
method(cr, job['user_id'], *args) |
||||
|
|
||||
|
except psycopg2.OperationalError, e: |
||||
|
# User friendly error if the lock could not be claimed |
||||
|
if e.pgcode == '55P03': |
||||
|
raise orm.except_orm( |
||||
|
_('Error'), |
||||
|
_('Another process/thread is already busy ' |
||||
|
'executing this job')) |
||||
|
raise |
||||
|
|
||||
|
return True |
@ -0,0 +1,20 @@ |
|||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||
|
<openerp> |
||||
|
<data> |
||||
|
|
||||
|
<record id="ir_cron_view" model="ir.ui.view"> |
||||
|
<field name="model">ir.cron</field> |
||||
|
<field name="inherit_id" ref="base.ir_cron_view" /> |
||||
|
<field name="arch" type="xml"> |
||||
|
<field name="args" position="after"> |
||||
|
<button name="run_manually" |
||||
|
string="Run now" |
||||
|
type="object" |
||||
|
/> |
||||
|
</field> |
||||
|
</field> |
||||
|
</record> |
||||
|
|
||||
|
</data> |
||||
|
</openerp> |
||||
|
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue