Skip to content

Commit eea20ec

Browse files
committed
preluare job queue din 14
1 parent effb03d commit eea20ec

25 files changed

+2482
-0
lines changed

deltatech_queue_job/README.rst

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
===================
2+
Deltatech Queue Job
3+
===================
4+
5+
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6+
!! This file is generated by oca-gen-addon-readme !!
7+
!! changes will be overwritten. !!
8+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
9+
10+
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
11+
:target: https://odoo-community.org/page/development-status
12+
:alt: Beta
13+
.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png
14+
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
15+
:alt: License: LGPL-3
16+
.. |badge3| image:: https://img.shields.io/badge/github-dhongu%2Fdeltatech-lightgray.png?logo=github
17+
:target: https://github.com/dhongu/deltatech/tree/14.0/deltatech_queue_job
18+
:alt: dhongu/deltatech
19+
20+
|badge1| |badge2| |badge3|
21+
22+
23+
**Table of contents**
24+
25+
.. contents::
26+
:local:
27+
28+
Bug Tracker
29+
===========
30+
31+
Bugs are tracked on `GitHub Issues <https://github.com/dhongu/deltatech/issues>`_.
32+
In case of trouble, please check there if your issue has already been reported.
33+
If you spotted it first, help us smashing it by providing a detailed and welcomed
34+
`feedback <https://github.com/dhongu/deltatech/issues/new?body=module:%20deltatech_queue_job%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
35+
36+
Do not contact contributors directly about support or help with technical issues.
37+
38+
Credits
39+
=======
40+
41+
Authors
42+
~~~~~~~
43+
44+
* Terrabit
45+
* Dorin Hongu
46+
* Camptocamp
47+
* ACSONE SA/NV
48+
49+
Maintainers
50+
~~~~~~~~~~~
51+
52+
.. |maintainer-dhongu| image:: https://github.com/dhongu.png?size=40px
53+
:target: https://github.com/dhongu
54+
:alt: dhongu
55+
56+
Current maintainer:
57+
58+
|maintainer-dhongu|
59+
60+
This module is part of the `dhongu/deltatech <https://github.com/dhongu/deltatech/tree/14.0/deltatech_queue_job>`_ project on GitHub.
61+
62+
You are welcome to contribute.

deltatech_queue_job/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# © 2021 Deltatech
2+
# See README.rst file on addons root folder for license details
3+
4+
from . import models
5+
from . import wizards

deltatech_queue_job/__manifest__.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# © 2015-2019 Deltatech
2+
# See README.rst file on addons root folder for license details
3+
{
4+
"name": "Deltatech Queue Job",
5+
"summary": "Queue Job using Crone",
6+
"version": "15.0.1.0.1",
7+
"author": "Terrabit, Dorin Hongu, Camptocamp,ACSONE SA/NV,Odoo Community Association (OCA)",
8+
"website": "https://www.terrabit.ro",
9+
"support": "[email protected]",
10+
"category": "Warehouse",
11+
"depends": ["base", "mail"],
12+
"data": [
13+
"security/security.xml",
14+
"security/ir.model.access.csv",
15+
"views/queue_job_views.xml",
16+
"views/queue_job_menus.xml",
17+
"data/ir_cron_data.xml",
18+
"wizards/queue_jobs_to_done_views.xml",
19+
"wizards/queue_requeue_job_views.xml",
20+
],
21+
"license": "LGPL-3",
22+
"images": ["static/description/main_screenshot.png"],
23+
"development_status": "Beta",
24+
"maintainers": ["dhongu"],
25+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?xml version='1.0' encoding='utf-8' ?>
2+
<odoo>
3+
<data noupdate="1">
4+
<record id="ir_cron_queue_job" model="ir.cron">
5+
<field name="name">Queue: Run</field>
6+
<field name="model_id" ref="model_queue_job" />
7+
<field name="state">code</field>
8+
<field name="numbercall">-1</field>
9+
<field name="code">model._cron_runjob()</field>
10+
<field name="interval_number">1</field>
11+
<field name="interval_type">minutes</field>
12+
<field name="user_id" ref="base.user_root" />
13+
<field name="active" eval="True" />
14+
<field name="doall" eval="False" />
15+
</record>
16+
<record id="ir_cron_autovacuum_queue_jobs" model="ir.cron">
17+
<field name="name">AutoVacuum Job Queue</field>
18+
<field name="model_id" ref="model_queue_job" />
19+
<field eval="True" name="active" />
20+
<field name="user_id" ref="base.user_root" />
21+
<field name="interval_number">1</field>
22+
<field name="interval_type">days</field>
23+
<field name="numbercall">-1</field>
24+
<field eval="False" name="doall" />
25+
<field name="state">code</field>
26+
<field name="code">model.autovacuum()</field>
27+
</record>
28+
</data>
29+
30+
<!-- Queue-job-related subtypes for messaging / Chatter -->
31+
<record id="mt_job_failed" model="mail.message.subtype">
32+
<field name="name">Job failed</field>
33+
<field name="res_model">queue.job</field>
34+
<field name="default" eval="True" />
35+
</record>
36+
</odoo>

deltatech_queue_job/exception.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Copyright 2012-2016 Camptocamp
2+
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html)
3+
4+
5+
class BaseQueueJobError(Exception):
6+
"""Base queue job error"""
7+
8+
9+
class JobError(BaseQueueJobError):
10+
"""A job had an error"""
11+
12+
13+
class NoSuchJobError(JobError):
14+
"""The job does not exist."""
15+
16+
17+
class FailedJobError(JobError):
18+
"""A job had an error having to be resolved."""
19+
20+
21+
class RetryableJobError(JobError):
22+
"""A job had an error but can be retried.
23+
24+
The job will be retried after the given number of seconds. If seconds is
25+
empty, it will be retried according to the ``retry_pattern`` of the job or
26+
by :const:`odoo.addons.queue_job.job.RETRY_INTERVAL` if nothing is defined.
27+
28+
If ``ignore_retry`` is True, the retry counter will not be increased.
29+
"""
30+
31+
def __init__(self, msg, seconds=None, ignore_retry=False):
32+
super().__init__(msg)
33+
self.seconds = seconds
34+
self.ignore_retry = ignore_retry
35+
36+
37+
# TODO: remove support of NothingToDo: too dangerous
38+
class NothingToDoJob(JobError):
39+
"""The Job has nothing to do."""
40+
41+
42+
class ChannelNotFound(BaseQueueJobError):
43+
"""A channel could not be found"""

deltatech_queue_job/fields.py

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
# copyright 2016 Camptocamp
2+
# license lgpl-3.0 or later (http://www.gnu.org/licenses/lgpl.html)
3+
4+
import json
5+
from datetime import date, datetime
6+
7+
import dateutil
8+
import lxml
9+
10+
from odoo import fields, models
11+
from odoo.tools.func import lazy
12+
13+
14+
class JobSerialized(fields.Field):
15+
"""Provide the storage for job fields stored as json
16+
17+
A base_type must be set, it must be dict, list or tuple.
18+
When the field is not set, the json will be the corresponding
19+
json string ("{}" or "[]").
20+
21+
Support for some custom types has been added to the json decoder/encoder
22+
(see JobEncoder and JobDecoder).
23+
"""
24+
25+
type = "job_serialized"
26+
column_type = ("text", "text")
27+
28+
_base_type = None
29+
30+
# these are the default values when we convert an empty value
31+
_default_json_mapping = {
32+
dict: "{}",
33+
list: "[]",
34+
tuple: "[]",
35+
models.BaseModel: lambda env: json.dumps(
36+
{"_type": "odoo_recordset", "model": "base", "ids": [], "uid": env.uid}
37+
),
38+
}
39+
40+
def __init__(self, string=fields.Default, base_type=fields.Default, **kwargs):
41+
super().__init__(string=string, _base_type=base_type, **kwargs)
42+
43+
def _setup_attrs(self, model, name):
44+
super()._setup_attrs(model, name)
45+
if self._base_type not in self._default_json_mapping:
46+
raise ValueError("%s is not a supported base type" % (self._base_type))
47+
48+
def _base_type_default_json(self, env):
49+
default_json = self._default_json_mapping.get(self._base_type)
50+
if not isinstance(default_json, str):
51+
default_json = default_json(env)
52+
return default_json
53+
54+
def convert_to_column(self, value, record, values=None, validate=True):
55+
return self.convert_to_cache(value, record, validate=validate)
56+
57+
def convert_to_cache(self, value, record, validate=True):
58+
# cache format: json.dumps(value) or None
59+
if isinstance(value, self._base_type):
60+
return json.dumps(value, cls=JobEncoder)
61+
else:
62+
return value or None
63+
64+
def convert_to_record(self, value, record):
65+
default = self._base_type_default_json(record.env)
66+
return json.loads(value or default, cls=JobDecoder, env=record.env)
67+
68+
69+
class JobEncoder(json.JSONEncoder):
70+
"""Encode Odoo recordsets so that we can later recompose them"""
71+
72+
def default(self, obj):
73+
if isinstance(obj, models.BaseModel):
74+
return {
75+
"_type": "odoo_recordset",
76+
"model": obj._name,
77+
"ids": obj.ids,
78+
"uid": obj.env.uid,
79+
"su": obj.env.su,
80+
}
81+
elif isinstance(obj, datetime):
82+
return {"_type": "datetime_isoformat", "value": obj.isoformat()}
83+
elif isinstance(obj, date):
84+
return {"_type": "date_isoformat", "value": obj.isoformat()}
85+
elif isinstance(obj, lxml.etree._Element):
86+
return {
87+
"_type": "etree_element",
88+
"value": lxml.etree.tostring(obj, encoding=str),
89+
}
90+
elif isinstance(obj, lazy):
91+
return obj._value
92+
return json.JSONEncoder.default(self, obj)
93+
94+
95+
class JobDecoder(json.JSONDecoder):
96+
"""Decode json, recomposing recordsets"""
97+
98+
def __init__(self, *args, **kwargs):
99+
env = kwargs.pop("env")
100+
super().__init__(object_hook=self.object_hook, *args, **kwargs)
101+
assert env
102+
self.env = env
103+
104+
def object_hook(self, obj):
105+
if "_type" not in obj:
106+
return obj
107+
type_ = obj["_type"]
108+
if type_ == "odoo_recordset":
109+
model = self.env(user=obj.get("uid"), su=obj.get("su"))[obj["model"]]
110+
111+
return model.browse(obj["ids"])
112+
elif type_ == "datetime_isoformat":
113+
return dateutil.parser.parse(obj["value"])
114+
elif type_ == "date_isoformat":
115+
return dateutil.parser.parse(obj["value"]).date()
116+
elif type_ == "etree_element":
117+
return lxml.etree.fromstring(obj["value"])
118+
return obj

0 commit comments

Comments
 (0)