Browse Source

[ADD] cron_run_manually: Tool for allowing run manually a programmed task

pull/117/head
Pedro M. Baeza 9 years ago
parent
commit
2f94f006e3
  1. 1
      cron_run_manually/__init__.py
  2. 37
      cron_run_manually/__openerp__.py
  3. 47
      cron_run_manually/i18n/cron_run_manually.pot
  4. 41
      cron_run_manually/i18n/es.po
  5. 47
      cron_run_manually/i18n/nl.po
  6. 1
      cron_run_manually/model/__init__.py
  7. 82
      cron_run_manually/model/ir_cron.py
  8. 20
      cron_run_manually/view/ir_cron.xml

1
cron_run_manually/__init__.py

@ -0,0 +1 @@
from . import model

37
cron_run_manually/__openerp__.py

@ -0,0 +1,37 @@
# -*- 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'],
'installable': True,
}

47
cron_run_manually/i18n/cron_run_manually.pot

@ -0,0 +1,47 @@
# 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: 2014-03-14 17:41+0000\n"
"PO-Revision-Date: 2014-03-14 17:41+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:77
#, python-format
msgid "Another process/thread is already busy executing this job"
msgstr ""
#. module: cron_run_manually
#: view:ir.cron:0
msgid "Run now"
msgstr ""
#. module: cron_run_manually
#: code:addons/cron_run_manually/model/ir_cron.py:52
#, python-format
msgid "Only the admin user is allowed to execute inactive cron jobs manually"
msgstr ""
#. module: cron_run_manually
#: model:_description:0
#: model:ir.model,name:cron_run_manually.model_ir_cron
msgid "ir.cron"
msgstr ""
#. module: cron_run_manually
#: code:addons/cron_run_manually/model/ir_cron.py:51
#: code:addons/cron_run_manually/model/ir_cron.py:76
#, python-format
msgid "Error"
msgstr ""

41
cron_run_manually/i18n/es.po

@ -0,0 +1,41 @@
# 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: 2014-03-14 17:41+0000\n"
"PO-Revision-Date: 2014-03-14 17:41+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:77
#, python-format
msgid "Another process/thread is already busy executing this job"
msgstr "Otro proceso/hilo está ya ocupado ejecutando esta tarea"
#. module: cron_run_manually
#: view:ir.cron:0
msgid "Run now"
msgstr "Ejecutar ahora"
#. module: cron_run_manually
#: code:addons/cron_run_manually/model/ir_cron.py:52
#, python-format
msgid "Only the admin user is allowed to execute inactive cron jobs manually"
msgstr "Sólo el usuario administrador puede ejecutar manualmente tareas inactivas"
#. module: cron_run_manually
#: code:addons/cron_run_manually/model/ir_cron.py:51
#: code:addons/cron_run_manually/model/ir_cron.py:76
#, python-format
msgid "Error"
msgstr "Error"

47
cron_run_manually/i18n/nl.po

@ -0,0 +1,47 @@
# 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: 2014-03-14 17:41+0000\n"
"PO-Revision-Date: 2014-01-20 14:09+0000\n"
"Last-Translator: michele <michelemilidoni@gmail.com>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Launchpad-Export-Date: 2014-05-24 06:46+0000\n"
"X-Generator: Launchpad (build 17017)\n"
#. module: cron_run_manually
#: code:addons/cron_run_manually/model/ir_cron.py:77
#, 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
#: code:addons/cron_run_manually/model/ir_cron.py:52
#, python-format
msgid "Only the admin user is allowed to execute inactive cron jobs manually"
msgstr ""
#. module: cron_run_manually
#: model:_description:0
#: 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:51
#: code:addons/cron_run_manually/model/ir_cron.py:76
#, python-format
msgid "Error"
msgstr "Fout"

1
cron_run_manually/model/__init__.py

@ -0,0 +1 @@
from . import ir_cron

82
cron_run_manually/model/ir_cron.py

@ -0,0 +1,82 @@
# -*- 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 import SUPERUSER_ID
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:
if uid != SUPERUSER_ID and (
not job['active'] or not job['numbercall']):
raise orm.except_orm(
_('Error'),
_('Only the admin user is allowed to '
'execute inactive cron jobs manually'))
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 as 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

20
cron_run_manually/view/ir_cron.xml

@ -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>
Loading…
Cancel
Save