Skip to content

Commit

Permalink
Merge pull request #343 from OCA/17.0
Browse files Browse the repository at this point in the history
Syncing from upstream OCA/queue (17.0)
  • Loading branch information
bt-admin authored Jan 26, 2024
2 parents 580a75a + 78ad392 commit b75a2ed
Show file tree
Hide file tree
Showing 23 changed files with 888 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Available addons
addon | version | maintainers | summary
--- | --- | --- | ---
[queue_job](queue_job/) | 17.0.1.0.0 | [![guewen](https://github.com/guewen.png?size=30px)](https://github.com/guewen) | Job Queue
[queue_job_cron](queue_job_cron/) | 17.0.1.0.0 | | Scheduled Actions as Queue Jobs
[queue_job_cron_jobrunner](queue_job_cron_jobrunner/) | 17.0.1.0.0 | [![ivantodorovich](https://github.com/ivantodorovich.png?size=30px)](https://github.com/ivantodorovich) | Run jobs without a dedicated JobRunner
[queue_job_subscribe](queue_job_subscribe/) | 17.0.1.0.0 | | Control which users are subscribed to queue job notifications
[test_queue_job](test_queue_job/) | 17.0.1.0.0 | | Queue Job Tests
Expand Down
100 changes: 100 additions & 0 deletions queue_job_cron/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
===============================
Scheduled Actions as Queue Jobs
===============================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:c790b0e3494e59c709d57d7dbb0864ac37ce3af23801499f352df7528d5fe072
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fqueue-lightgray.png?logo=github
:target: https://github.com/OCA/queue/tree/17.0/queue_job_cron
:alt: OCA/queue
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/queue-17-0/queue-17-0-queue_job_cron
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/queue&target_branch=17.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module extends the functionality of queue_job and allows to run an
Odoo cron as a queue job.

**Table of contents**

.. contents::
:local:

Installation
============

To install this module, you need to:

1. Just install it.

Usage
=====

To use this module, you need to:

#. Go to a scheduled action, a flag "Run as queue job" will allow you to
run the action as a queue job. You will also allowed to select a channel
of its execution. To configure dedicated channels please refers to
queue_job help:
https://github.com/OCA/queue/blob/12.0/queue_job/README.rst

Channels can be used to manage sequential jobs and prevent concurrency
accesses. To do that you just have to define a channel per cron limited
to 1 at time.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/queue/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/queue/issues/new?body=module:%20queue_job_cron%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
-------

* ACSONE SA/NV

Contributors
------------

- Cédric Pigeon <[email protected]>
- Nguyen Minh Chien <[email protected]>

Maintainers
-----------

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/queue <https://github.com/OCA/queue/tree/17.0/queue_job_cron>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions queue_job_cron/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
14 changes: 14 additions & 0 deletions queue_job_cron/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright 2019 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)

{
"name": "Scheduled Actions as Queue Jobs",
"version": "17.0.1.0.0",
"author": "ACSONE SA/NV,Odoo Community Association (OCA)",
"website": "https://github.com/OCA/queue",
"license": "AGPL-3",
"category": "Generic Modules",
"depends": ["queue_job"],
"data": ["data/data.xml", "views/ir_cron_view.xml"],
"installable": True,
}
12 changes: 12 additions & 0 deletions queue_job_cron/data/data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record model="queue.job.channel" id="channel_root_ir_cron">
<field name="name">ir_cron</field>
<field name="parent_id" ref="queue_job.channel_root" />
</record>
<record model="queue.job.function" id="job_function_ir_cron_run_job_as_queue_job">
<field name="model_id" ref="base.model_ir_cron" />
<field name="method">_compute_run_as_queue_job</field>
<field name="channel_id" ref="channel_root_ir_cron" />
</record>
</odoo>
39 changes: 39 additions & 0 deletions queue_job_cron/i18n/de.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * queue_job_cron
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 12.0\n"
"Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: 2019-07-12 14:43+0000\n"
"Last-Translator: Maria Sparenberg <[email protected]>\n"
"Language-Team: none\n"
"Language: de\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"
"X-Generator: Weblate 3.7.1\n"

#. module: queue_job_cron
#: model:ir.model.fields,field_description:queue_job_cron.field_ir_cron__channel_id
msgid "Channel"
msgstr "Kanal"

#. module: queue_job_cron
#: model:ir.model.fields,field_description:queue_job_cron.field_ir_cron__run_as_queue_job
msgid "Run As Queue Job"
msgstr "als Warteschlangen-Job ausführen"

#. module: queue_job_cron
#: model:ir.model,name:queue_job_cron.model_ir_cron
msgid "Scheduled Actions"
msgstr "Eingeplante Aktionen"

#. module: queue_job_cron
#: model:ir.model.fields,help:queue_job_cron.field_ir_cron__run_as_queue_job
msgid "Specify if this cron should be ran as a queue job"
msgstr ""
"Bitte spezifizieren, ob der Cron-Job als Warteschlangen-Job ausgeführt "
"werden soll."
39 changes: 39 additions & 0 deletions queue_job_cron/i18n/es.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * queue_job_cron
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: 2023-09-03 13:40+0000\n"
"Last-Translator: kikopeiro <[email protected]>\n"
"Language-Team: none\n"
"Language: es\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"
"X-Generator: Weblate 4.17\n"

#. module: queue_job_cron
#: model:ir.model.fields,field_description:queue_job_cron.field_ir_cron__channel_id
msgid "Channel"
msgstr "Canal"

#. module: queue_job_cron
#: model:ir.model.fields,field_description:queue_job_cron.field_ir_cron__run_as_queue_job
msgid "Run As Queue Job"
msgstr "Ejecutar como trabajo en cola"

#. module: queue_job_cron
#: model:ir.model,name:queue_job_cron.model_ir_cron
msgid "Scheduled Actions"
msgstr "Acciones planificadas"

#. module: queue_job_cron
#: model:ir.model.fields,help:queue_job_cron.field_ir_cron__run_as_queue_job
msgid "Specify if this cron should be ran as a queue job"
msgstr ""
"Especifica si esta acción planificada deberá ser ejecutada como un trabajo "
"en cola"
34 changes: 34 additions & 0 deletions queue_job_cron/i18n/queue_job_cron.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * queue_job_cron
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 17.0\n"
"Report-Msgid-Bugs-To: \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: queue_job_cron
#: model:ir.model.fields,field_description:queue_job_cron.field_ir_cron__channel_id
msgid "Channel"
msgstr ""

#. module: queue_job_cron
#: model:ir.model.fields,field_description:queue_job_cron.field_ir_cron__run_as_queue_job
msgid "Run As Queue Job"
msgstr ""

#. module: queue_job_cron
#: model:ir.model,name:queue_job_cron.model_ir_cron
msgid "Scheduled Actions"
msgstr ""

#. module: queue_job_cron
#: model:ir.model.fields,help:queue_job_cron.field_ir_cron__run_as_queue_job
msgid "Specify if this cron should be ran as a queue job"
msgstr ""
37 changes: 37 additions & 0 deletions queue_job_cron/i18n/zh_CN.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * queue_job_cron
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 12.0\n"
"Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: 2019-07-25 17:43+0000\n"
"Last-Translator: 黎伟杰 <[email protected]>\n"
"Language-Team: none\n"
"Language: zh_CN\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: nplurals=1; plural=0;\n"
"X-Generator: Weblate 3.7.1\n"

#. module: queue_job_cron
#: model:ir.model.fields,field_description:queue_job_cron.field_ir_cron__channel_id
msgid "Channel"
msgstr "频道"

#. module: queue_job_cron
#: model:ir.model.fields,field_description:queue_job_cron.field_ir_cron__run_as_queue_job
msgid "Run As Queue Job"
msgstr "作为队列作业运行"

#. module: queue_job_cron
#: model:ir.model,name:queue_job_cron.model_ir_cron
msgid "Scheduled Actions"
msgstr "安排的动作"

#. module: queue_job_cron
#: model:ir.model.fields,help:queue_job_cron.field_ir_cron__run_as_queue_job
msgid "Specify if this cron should be ran as a queue job"
msgstr "指定此cron是否应作为队列作业运行"
1 change: 1 addition & 0 deletions queue_job_cron/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import ir_cron
61 changes: 61 additions & 0 deletions queue_job_cron/models/ir_cron.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Copyright 2019 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)
import logging

from odoo import api, fields, models

_logger = logging.getLogger(__name__)


class IrCron(models.Model):
_inherit = "ir.cron"

run_as_queue_job = fields.Boolean(
help="Specify if this cron should be ran as a queue job"
)
channel_id = fields.Many2one(
comodel_name="queue.job.channel",
compute="_compute_run_as_queue_job",
readonly=False,
string="Channel",
)

@api.depends("run_as_queue_job")
def _compute_run_as_queue_job(self):
for cron in self:
if cron.run_as_queue_job and not cron.channel_id:
cron.channel_id = self.env.ref("queue_job_cron.channel_root_ir_cron").id
else:
cron.channel_id = False

def _run_job_as_queue_job(self, server_action):
return server_action.run()

def method_direct_trigger(self):
for cron in self:
if not cron.run_as_queue_job:
super(IrCron, cron).method_direct_trigger()
else:
_cron = cron.with_user(cron.user_id).with_context(
lastcall=cron.lastcall
)
_cron.with_delay(
priority=_cron.priority,
description=_cron.name,
channel=_cron.channel_id.complete_name,
)._run_job_as_queue_job(server_action=_cron.ir_actions_server_id)
return True

def _callback(self, cron_name, server_action_id, job_id):
cron = self.env["ir.cron"].sudo().browse(job_id)
if cron.run_as_queue_job:
server_action = self.env["ir.actions.server"].browse(server_action_id)
return self.with_delay(
priority=cron.priority,
description=cron.name,
channel=cron.channel_id.complete_name,
)._run_job_as_queue_job(server_action=server_action)
else:
return super()._callback(
cron_name=cron_name, server_action_id=server_action_id, job_id=job_id
)
3 changes: 3 additions & 0 deletions queue_job_cron/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
3 changes: 3 additions & 0 deletions queue_job_cron/readme/CONFIGURATION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
To configure this module, you need to:

#. Nothing special to do.
2 changes: 2 additions & 0 deletions queue_job_cron/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Cédric Pigeon \<<[email protected]>\>
- Nguyen Minh Chien \<<[email protected]>\>
2 changes: 2 additions & 0 deletions queue_job_cron/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This module extends the functionality of queue_job and allows to run an
Odoo cron as a queue job.
3 changes: 3 additions & 0 deletions queue_job_cron/readme/INSTALL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
To install this module, you need to:

1. Just install it.
11 changes: 11 additions & 0 deletions queue_job_cron/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
To use this module, you need to:

#\. Go to a scheduled action, a flag "Run as queue job" will allow you
to run the action as a queue job. You will also allowed to select a
channel of its execution. To configure dedicated channels please refers
to queue_job help:
<https://github.com/OCA/queue/blob/12.0/queue_job/README.rst>

Channels can be used to manage sequential jobs and prevent concurrency
accesses. To do that you just have to define a channel per cron limited
to 1 at time.
Binary file added queue_job_cron/static/description/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit b75a2ed

Please sign in to comment.