Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[18.0][MIG] queue_job: Migrate to 18.0 #692

Merged
merged 1,204 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
1204 commits
Select commit Hold shift + click to select a range
aba9a15
queue_job: add hook to customize stored values
simahawk Mar 29, 2021
069b6f6
queue_job: migration step to store exception data
simahawk Mar 29, 2021
f3b9c83
Fix display on exec_time on tree view as seconds
guewen May 31, 2021
99e0e8c
[IMP] queue_job: black, isort, prettier
dzungtran89 Nov 23, 2021
9543fea
Forward migration scripts from #309 #328
dzungtran89 Nov 23, 2021
922a626
queue_job: store exception name and message
simahawk Mar 29, 2021
88885f5
[FIX] queue_job: Migrations raising errors with OpenUpgrade
etobella Jun 22, 2021
bffa80d
[IMP] queue_job: Add cancelled state to queue.job
hbrunn May 14, 2021
6dc7b34
[IMP] queue_job: tests for wizards
hbrunn May 21, 2021
103a4bf
[IMP] queue_job: use a widget in eta field in queue job tree view
fernandahf Nov 9, 2021
14b15f9
queue_job: use parent channel if configured
simahawk Mar 11, 2022
465ddff
queue_job: update contributors
simahawk Mar 11, 2022
0ff5ee7
[UPD] Update queue_job.pot
Oct 31, 2022
6340b2d
[UPD] README.rst
OCA-git-bot Oct 31, 2022
d7b90e9
Update translation files
weblate Oct 31, 2022
064b41a
Store dependencies
guewen Jul 2, 2019
24a0288
Add wait dependencies state
guewen Jul 2, 2019
9bb0d17
Enqueue waiting jobs when parent jobs are done
guewen Jul 3, 2019
9a96d04
Optimize and make enqueue of waiting jobs more robust
guewen Jul 4, 2019
498eec9
Adapt views for state wait_dependencies
guewen Jul 5, 2019
dae8fde
Add API for Delayables
guewen Jul 5, 2019
e6c904d
Fix tests failing when test_queue_job is installed
guewen Jul 6, 2019
5156f04
Add widget to show job dependencies on UI
guewen Jul 9, 2019
4ad5010
Show the dependency widget in a tab
guewen Jul 11, 2019
6db198a
Add documentation on 'base' model public methods
guewen Oct 4, 2019
75d31dd
Improve loading of dependencies using batch read
guewen Oct 4, 2019
f0698bd
Use Delayable in DelayableRecordset
guewen Oct 4, 2019
84cf1a0
Add documentation
guewen May 24, 2021
1f73c7e
Add a graph UUID
guewen May 26, 2021
6178a3a
Hide some technical fields
guewen May 26, 2021
3dacb8e
Ignore requeues on dependency jobs waiting on parent jobs
guewen May 26, 2021
25e2007
Fix lint
guewen May 27, 2021
1100f72
Update vis-network js
guewen May 27, 2021
c4d7d76
Improve display of jobs graph widget
guewen May 27, 2021
0ee73bc
Add powerful context manager for running tests on jobs
guewen May 28, 2021
495027c
Set graph_uuid only once in DelayableGraph
guewen May 30, 2021
fa44561
Add docstrings on the new delayable classes
guewen May 30, 2021
8719a3a
Add option to generate a graph in create_test_job controller
guewen Jul 1, 2021
f4786e7
Improve graph widget
guewen Jul 1, 2021
0e070db
Add a smart button to open all the jobs of a graph
guewen Jul 1, 2021
7e1f06a
ix duplicate label
guewen Jul 1, 2021
9fdbab1
Fix graph widget now showing title as HTML
guewen Jul 1, 2021
9ad5f92
Improve graph widget performance
guewen Jul 1, 2021
d35a651
Escape strings passed to the graph js widget
guewen Jul 21, 2021
04914cf
Fix things required by odoo 14.0 or python 3.9
guewen Oct 26, 2022
da26173
Add documentation about handling of failures in a graph
guewen Jan 29, 2022
fc4ce5d
Fix equality of enqueued jobs
guewen Feb 2, 2022
e9f29cf
Use a python3.6 compatible data class
guewen Feb 2, 2022
53dc84b
Rename mock_jobs() to trap_jobs()
guewen Feb 3, 2022
c72f729
Rename dependency method done() to on_done()
guewen Feb 3, 2022
dfac03a
Migrate queue job graph/dependencies to 15.0
guewen Oct 24, 2022
3d24de8
Apply pre-commit on migration of jobs graph
guewen Oct 24, 2022
76e5fc6
[UPD] Update queue_job.pot
Nov 15, 2022
0cdd6b6
[UPD] README.rst
OCA-git-bot Nov 15, 2022
7e099dd
Update translation files
weblate Nov 15, 2022
7f742b1
[MIG] queue_job, test_queue_job: Forward port queue from 15.0
lmignon Nov 16, 2022
132cbda
[FIX] queue_job: fix invalid po files
lmignon Nov 22, 2022
dfe911d
[UPD] Update queue_job.pot
Nov 22, 2022
12f9ce6
queue_job 16.0.2.0.0
OCA-git-bot Nov 22, 2022
bf55d74
Update translation files
weblate Nov 22, 2022
78f8f69
[FIX] queue_job: UI glitches in 16.0 migration
StefanRijnhart Dec 14, 2022
663a0bb
[UPD] Update queue_job.pot
Dec 14, 2022
9f24f43
queue_job 16.0.2.1.0
OCA-git-bot Dec 14, 2022
9ae8a29
Update translation files
weblate Dec 14, 2022
06e1eee
[FIX] Patch Request._get_session_and_dbname to get db from URL
hugosantosred Jan 31, 2023
45e7542
[FIX] queue_job: Commit was removed, but that could be a problem if y…
etobella Feb 14, 2023
cd57b85
Translated using Weblate (Spanish)
FranciscoFactorLibre Feb 15, 2023
02aa058
[FIX] queue_job: delayable representation failed
etobella Dec 1, 2022
da313b9
Fix cursor already closed error on retryable errors
guewen Jun 21, 2022
6133673
[IMP] queue_job: add configuration options for
repodevs Nov 2, 2022
46d573c
[14.0][FIX] queue_job: fix read
sanchonuria Feb 9, 2023
f4b9509
queue_job 16.0.2.2.0
OCA-git-bot Feb 28, 2023
80d2cae
queue_job: unify no delay option
simahawk Feb 28, 2023
f2cc191
queue_job 16.0.2.2.1
OCA-git-bot Mar 29, 2023
3049029
[UPD] README.rst
OCA-git-bot Apr 2, 2023
db227a4
queue_job 16.0.2.3.0
OCA-git-bot Apr 2, 2023
7b04cbe
Handle cancelled state in job runner
sbidoul May 2, 2023
5ff0fbe
queue_job 16.0.2.3.1
OCA-git-bot May 4, 2023
2aaf7b9
Fix trap_jobs() recordset comparison
guewen May 9, 2023
e8a0cc1
Translated using Weblate (Spanish)
ramiadavid May 18, 2023
e2f05e6
Translated using Weblate (Spanish)
ramiadavid May 18, 2023
10045e7
queue_job 16.0.2.3.2
OCA-git-bot Jun 2, 2023
0bd567b
queue_job 16.0.2.4.0
OCA-git-bot Jun 2, 2023
3972063
[FIX] queue_job: runner - filedescriptor out of range in select
moylop260 Feb 15, 2022
79b835e
queue_job 16.0.2.5.0
OCA-git-bot Jun 30, 2023
637f28d
[UPD] Update queue_job.pot
Sep 3, 2023
70cfd17
[UPD] README.rst
OCA-git-bot Sep 3, 2023
7f5ba75
Update translation files
weblate Sep 3, 2023
9df0e54
Translated using Weblate (Spanish)
Ivorra78 Sep 7, 2023
816233c
Translated using Weblate (Spanish)
Ivorra78 Sep 20, 2023
e7a9eda
[UPD] Update queue_job.pot
Oct 28, 2023
1da9385
Update translation files
weblate Oct 29, 2023
583ec3d
[IMP] queue_job: identity_key enhancements
Jun 16, 2023
49d6b13
queue_job: job_record_with_same_identity_key ignore STARTED
simahawk Nov 21, 2023
c0af708
FIX queue_job avoiding AccessDenied when loading the module in an ins…
eLBati Oct 26, 2021
1ef21e0
queue job avoiding AccessDenied when loading the module in an instanc…
pcastelovigo Nov 22, 2023
2cdb41a
[BOT] post-merge updates
OCA-git-bot Nov 23, 2023
64442e4
[BOT] post-merge updates
OCA-git-bot Nov 23, 2023
a43f146
[IMP] queue_job: pre-commit auto fixes
nguyenminhchien Nov 29, 2023
e2403b9
[MIG] queue_job: Migration to 17.0
nguyenminhchien Dec 4, 2023
cc366aa
[UPD] Update queue_job.pot
Dec 5, 2023
b84ffb3
[BOT] post-merge updates
OCA-git-bot Dec 5, 2023
0d58e54
Update translation files
weblate Feb 3, 2024
a9b85bc
Added translation using Weblate (Italian)
mymage Feb 5, 2024
c3b6eea
Translated using Weblate (Italian)
mymage Feb 16, 2024
6f4f68c
Translated using Weblate (Italian)
mymage Feb 19, 2024
5ddbc15
Remove doctest from get_db_names method to avoid issues with Odoo.sh
AlexanderPashuk Mar 13, 2024
c99094a
[BOT] post-merge updates
OCA-git-bot Apr 4, 2024
bb918e6
[FIX] *queue_job: Pre-commit fixes
pedrobaeza May 1, 2024
5896769
[BOT] post-merge updates
OCA-git-bot May 1, 2024
0981244
[fix] queue_job: JobsTrap.perform_enqueued_jobs
fd-oncodna May 22, 2024
a22ca58
[BOT] post-merge updates
OCA-git-bot May 25, 2024
3f4e170
Translated using Weblate (Chinese (Simplified) (zh_CN))
xtanuiha Jul 2, 2024
b567012
[14.0][IMP] queue_job current company
acsonefho Aug 2, 2021
5329361
queue_job: fix pylint duplicate-xml-fields
simahawk Mar 14, 2022
fbdd23f
Revert "[14.0][IMP] queue_job current company"
sbidoul Oct 18, 2022
1b1ebac
IMP queue_job: add cancelled filter
hparfr Jan 3, 2023
35ce82b
queue_job: split identity_key hasher to ease reuse
simahawk Nov 27, 2023
f0baf49
[IMP] queue_job: track error in chatter
MiquelRForgeFlow Nov 16, 2023
d6e0a61
queue_job: fix partial index to add 'wait_dependencies' state
sebalix Mar 6, 2024
c99d000
queue_job: triggers stored computed fields before calling 'set_done()'
sebalix Mar 27, 2024
219aac0
queue_job: fix retry format with tuple values
InigoGR Feb 1, 2024
41db069
[IMP] queue_job: Cancel child jobs when the parent is cancelled
QuocDuong1306 Aug 1, 2024
75c0104
[FIX] queue_job: typo
florentx Sep 16, 2024
4153868
[IMP] queue_job: add filter on Date Created
florentx Sep 16, 2024
13d2f05
[IMP] queue_job: pre-commit auto fixes
nguyenminhchien Nov 29, 2023
63dd90d
[IMP] queue_job: Display warning before displaying big dependency graphs
paradoxxxzero Jun 4, 2024
3c98e95
[MIG] queue_job: Migration to 18.0
QuocDuong1306 Sep 19, 2024
8c92c88
[IMP] queue_job: Cleaned TODO tags
QuocDuong1306 Sep 25, 2024
3383dbd
[IMP] queue_job: use jsonb column for JobSerialized
QuocDuong1306 Sep 26, 2024
147b5e8
Make tests pass
guewen Dec 29, 2016
6c73fec
Fix implementation of related actions
guewen Dec 29, 2016
742d825
Move tests using queue_job.testing_method in test_queue_job
guewen Dec 30, 2016
511c701
Fix mutability of job arguments
guewen Jan 2, 2017
4c7a5cf
[IMP] Allow to override the channel to use when delaying a job
lmignon Mar 29, 2017
4398649
[FIX] domain to subscribe users
GillesTephaneMeyomesse May 26, 2017
44b8ec8
[MIG] Make modules uninstallable
pedrobaeza Oct 2, 2017
b274c52
Set test_queue_job installable to work on tests
guewen Oct 2, 2017
ec1ab98
PY3: replace im_class and so with __self__
guewen Oct 2, 2017
243d1bd
PY3: remove encode/decode in a test
guewen Oct 2, 2017
de4d3bc
Correct or disable pylint warnings
guewen May 25, 2018
e21d74b
Fix auto registration of job methods and channels
guewen May 22, 2018
cc2211c
Add default related action to open related records
guewen Jan 24, 2018
df78b3c
[MIG] Make modules uninstallable
OCA-git-bot Sep 27, 2018
561a88e
Migrate queue_job to 12.0
guewen Oct 1, 2018
2748465
[11.0] Forward port. of identity_key (from 10.0)
guewen Jun 28, 2018
ee4d158
[UPD] Update test_queue_job.pot
oca-travis Dec 13, 2018
7b8bd0f
[ADD] icon.png
OCA-git-bot Apr 2, 2019
aa19de4
[ADD] Test case for "AutoVacuum Job Queue" cron job
Aug 3, 2019
16365cb
Added translation using Weblate (Chinese (Simplified))
liweijie0812 Aug 31, 2019
dedfe29
Translated using Weblate (Chinese (Simplified))
liweijie0812 Aug 31, 2019
b65e903
Set modules as uninstallable
guewen Oct 1, 2019
5b41193
Migrate queue_job
guewen Oct 1, 2019
16afd38
Replace sudo(user) by with_user(user)
guewen Oct 1, 2019
3c35e28
Run pre-commit with black, isort, ...
guewen Oct 4, 2019
2f03ca3
[UPD] Update test_queue_job.pot
oca-travis Oct 15, 2019
4653796
Use more permissive license AGPL3 → LGPL3
guewen Oct 31, 2019
3531e21
queue_job: allow to define vacuum removal interval per channel
Nov 7, 2019
092a331
Move autovacuum tests in the same class
guewen Nov 8, 2019
034806d
[FIX] queue_job: vaccuum query must be based on channel complete name
Nov 27, 2019
81edc98
Store worker's PID when a job is started
guewen Oct 1, 2020
adfdeaf
Deprecate job decorators
guewen Oct 30, 2020
68ce406
Replace job function name by model + method fields
guewen Nov 2, 2020
5b9b096
test_queue_job 13.0.2.0.0
OCA-git-bot Nov 12, 2020
4bf174a
test_queue_job 13.0.2.1.0
OCA-git-bot Nov 13, 2020
9b309d9
Refactor user_id,model_name,record_ids fields on queue.job
guewen Oct 29, 2020
060c835
Store 'su' flag in records stored in JobSerialized fields
guewen Nov 13, 2020
c0f18ab
[MIG] init V14 repo
sebastienbeau Nov 20, 2020
ce1a57a
[IMP] : black, isort, prettier
sebastienbeau Nov 20, 2020
9ddf120
[REF] remove deprecated feature
sebastienbeau Nov 20, 2020
94e6430
[MIG] finish migration
sebastienbeau Nov 20, 2020
bed8b8f
Add import shortcut for identity_exact
guewen Nov 28, 2020
799a99b
[UPD] Update test_queue_job.pot
oca-travis Nov 30, 2020
3f1987d
[REF] Replace deprecated assertEquals with assertEqual
PieterPaulussen Mar 23, 2021
10f48f6
[FIX] use __func__ for function comparison in tests
PieterPaulussen Apr 6, 2021
36cff9a
[IMP] Store job execution information + wizard to terminate a job + test
PieterPaulussen Mar 23, 2021
e2e05a0
[ADD] Apply suggestions from code review
Apr 20, 2021
eea6f31
[UPD] Update test_queue_job.pot
oca-travis May 4, 2021
8877111
test_queue_job 14.0.1.1.0
OCA-git-bot May 4, 2021
905befb
Update translation files
oca-transbot May 4, 2021
54e9ed6
Revert "[14.0] [IMP] Store job execution information + wizard to term…
guewen May 11, 2021
85859b0
[UPD] Update test_queue_job.pot
oca-travis May 12, 2021
ae5aa9a
test_queue_job 14.0.1.2.0
OCA-git-bot May 12, 2021
bcaf26a
Update translation files
oca-transbot May 12, 2021
7c2cb3b
Add method to patch a method to be automatically delayed
guewen Oct 28, 2020
adff9ed
test_queue_job 14.0.1.3.0
OCA-git-bot May 27, 2021
8b648eb
Set modules as uninstallable
guewen Nov 1, 2021
384dc98
Set modules queue_job and test_queue_job as installable
guewen Nov 1, 2021
dcce1d2
Run pre-commit run -a
guewen Nov 1, 2021
355c223
[MIG] test_queue_job: Migration to 15.0
guewen Nov 1, 2021
deebb12
[UPD] Update test_queue_job.pot
Nov 2, 2021
4e4956e
[IMP] update dotfiles [ci skip]
OCA-git-bot Mar 31, 2022
f90cec2
Initialize 16.0
sbidoul Oct 3, 2022
a0daa51
[MIG] test_queue_job: Migration to 16.0
baimont Oct 11, 2022
2893087
[FIX] import mock from unittest
baimont Oct 11, 2022
48464b7
[UPD] Update test_queue_job.pot
Oct 11, 2022
415e0b1
[UPD] Update test_queue_job.pot
Oct 18, 2022
a2e5f2e
Update translation files
weblate Oct 18, 2022
d8e6409
Disable storing of context in jobs recordsets by default
guewen May 12, 2022
4df9680
test_queue_job 16.0.1.0.1
OCA-git-bot Oct 26, 2022
a33168d
Added translation using Weblate (German)
marylla Nov 4, 2022
f6c5b67
Translated using Weblate (German)
marylla Nov 4, 2022
4faa9ac
Remove initial create notification and follower
guewen Feb 1, 2021
500fd47
queue_job: add exec time to view some stats
simahawk Feb 8, 2021
964e093
queue_job: add hook to customize stored values
simahawk Mar 29, 2021
024e6ad
queue_job: store exception name and message
simahawk Mar 29, 2021
7980a08
[UPD] Update test_queue_job.pot
Oct 31, 2022
a24652a
Update translation files
weblate Oct 31, 2022
c3653e0
Store dependencies
guewen Jul 2, 2019
309948a
Add wait dependencies state
guewen Jul 2, 2019
deb5efb
Add API for Delayables
guewen Jul 5, 2019
b10eddc
Add a graph UUID
guewen May 26, 2021
e85778e
Ignore requeues on dependency jobs waiting on parent jobs
guewen May 26, 2021
bd74a9c
Fix warnings in tests
guewen May 27, 2021
4795fa5
Improve display of jobs graph widget
guewen May 27, 2021
3cc8c41
Add powerful context manager for running tests on jobs
guewen May 28, 2021
574382c
Set graph_uuid only once in DelayableGraph
guewen May 30, 2021
c4079c3
Add docstrings on the new delayable classes
guewen May 30, 2021
50dd727
Fix things required by odoo 14.0 or python 3.9
guewen Oct 26, 2022
7d27c13
Rename mock_jobs() to trap_jobs()
guewen Feb 3, 2022
405b5cc
Rename dependency method done() to on_done()
guewen Feb 3, 2022
3b00e1a
Apply pre-commit on migration of jobs graph
guewen Oct 24, 2022
8d78fc6
Use new TransactionCase instead of deprecated SavepointCase
guewen Oct 24, 2022
31b6246
[MIG] queue_job, test_queue_job: Forward port queue from 15.0
lmignon Nov 16, 2022
f8b3c3f
test_queue_job 16.0.2.0.0
OCA-git-bot Nov 22, 2022
a867251
Update translation files
weblate Nov 22, 2022
9ab23bf
queue_job: unify no delay option
simahawk Feb 28, 2023
b29b1db
test_queue_job 16.0.2.1.0
OCA-git-bot Apr 2, 2023
339d056
Fix trap_jobs() recordset comparison
guewen May 9, 2023
0c6b77c
test_queue_job 16.0.2.2.0
OCA-git-bot Jun 2, 2023
2e4061d
Added translation using Weblate (Spanish)
Ivorra78 Oct 15, 2023
f13d768
Translated using Weblate (Spanish)
Ivorra78 Oct 15, 2023
d880af4
[IMP] queue_job: identity_key enhancements
Jun 16, 2023
c874af9
[BOT] post-merge updates
OCA-git-bot Nov 23, 2023
dc7b476
[IMP] test_queue_job: pre-commit auto fixes
nguyenminhchien Nov 29, 2023
e60af34
[MIG] test_queue_job: Migration to 17.0
nguyenminhchien Nov 29, 2023
8a44ad6
[UPD] Update test_queue_job.pot
Dec 5, 2023
99ac109
Update translation files
weblate Feb 3, 2024
8139b65
Added translation using Weblate (Italian)
mymage Feb 4, 2024
cbabd2e
Translated using Weblate (Italian)
mymage Feb 12, 2024
a00a224
[FIX] *queue_job: Pre-commit fixes
pedrobaeza May 1, 2024
77157c2
[BOT] post-merge updates
OCA-git-bot May 1, 2024
5537e6f
Translated using Weblate (Chinese (Simplified) (zh_CN))
xtanuiha Jul 2, 2024
eefbcaf
[14.0][IMP] queue_job current company
acsonefho Aug 2, 2021
35f23af
Update test with proper way to pass company to job
sbidoul Oct 18, 2022
2941c11
queue_job: fix retry format with tuple values
InigoGR Feb 1, 2024
531227d
[FIX] queue_job: missing flush
QuocDuong1306 Jul 29, 2024
ec1c4c0
[IMP] queue_job: Cancel child jobs when the parent is cancelled
QuocDuong1306 Aug 1, 2024
eb6c5dd
[IMP] queue_job: Don't raise a warning for valid context
rousseldenis Aug 23, 2024
bb4b6f6
[MIG] test_queue_job: Migration to 18.0
QuocDuong1306 Sep 24, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
685 changes: 685 additions & 0 deletions queue_job/README.rst

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions queue_job/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from . import controllers
from . import fields
from . import models
from . import wizards
from . import jobrunner
from .post_init_hook import post_init_hook
from .post_load import post_load

# shortcuts
from .job import identity_exact
35 changes: 35 additions & 0 deletions queue_job/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html)

{
"name": "Job Queue",
"version": "18.0.1.0.0",
"author": "Camptocamp,ACSONE SA/NV,Odoo Community Association (OCA)",
"website": "https://github.com/OCA/queue",
"license": "LGPL-3",
"category": "Generic Modules",
"depends": ["mail", "base_sparse_field", "web"],
"external_dependencies": {"python": ["requests"]},
"data": [
"security/security.xml",
"security/ir.model.access.csv",
"views/queue_job_views.xml",
"views/queue_job_channel_views.xml",
"views/queue_job_function_views.xml",
"wizards/queue_jobs_to_done_views.xml",
"wizards/queue_jobs_to_cancelled_views.xml",
"wizards/queue_requeue_job_views.xml",
"views/queue_job_menus.xml",
"data/queue_data.xml",
"data/queue_job_function_data.xml",
],
"assets": {
"web.assets_backend": [
"/queue_job/static/src/views/**/*",
],
},
"installable": True,
"development_status": "Mature",
"maintainers": ["guewen"],
"post_init_hook": "post_init_hook",
"post_load": "post_load",
}
1 change: 1 addition & 0 deletions queue_job/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import main
289 changes: 289 additions & 0 deletions queue_job/controllers/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,289 @@
# Copyright (c) 2015-2016 ACSONE SA/NV (<http://acsone.eu>)
# Copyright 2013-2016 Camptocamp SA
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html)

import logging
import random
import time
import traceback
from io import StringIO

from psycopg2 import OperationalError, errorcodes
from werkzeug.exceptions import BadRequest, Forbidden

from odoo import SUPERUSER_ID, _, api, http, registry
from odoo.service.model import PG_CONCURRENCY_ERRORS_TO_RETRY

from ..delay import chain, group
from ..exception import FailedJobError, RetryableJobError
from ..job import ENQUEUED, Job

_logger = logging.getLogger(__name__)

PG_RETRY = 5 # seconds

DEPENDS_MAX_TRIES_ON_CONCURRENCY_FAILURE = 5


class RunJobController(http.Controller):
def _try_perform_job(self, env, job):
"""Try to perform the job."""
job.set_started()
job.store()
env.cr.commit()
_logger.debug("%s started", job)

job.perform()
# Triggers any stored computed fields before calling 'set_done'
# so that will be part of the 'exec_time'
env.flush_all()

Check warning on line 39 in queue_job/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

queue_job/controllers/main.py#L39

Added line #L39 was not covered by tests
job.set_done()
job.store()
env.flush_all()
env.cr.commit()
_logger.debug("%s done", job)

def _enqueue_dependent_jobs(self, env, job):
tries = 0
while True:
try:
job.enqueue_waiting()
except OperationalError as err:

Check warning on line 51 in queue_job/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

queue_job/controllers/main.py#L47-L51

Added lines #L47 - L51 were not covered by tests
# Automatically retry the typical transaction serialization
# errors
if err.pgcode not in PG_CONCURRENCY_ERRORS_TO_RETRY:
raise

Check warning on line 55 in queue_job/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

queue_job/controllers/main.py#L55

Added line #L55 was not covered by tests
if tries >= DEPENDS_MAX_TRIES_ON_CONCURRENCY_FAILURE:
_logger.info(

Check warning on line 57 in queue_job/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

queue_job/controllers/main.py#L57

Added line #L57 was not covered by tests
"%s, maximum number of tries reached to update dependencies",
errorcodes.lookup(err.pgcode),
)
raise
wait_time = random.uniform(0.0, 2**tries)
tries += 1
_logger.info(

Check warning on line 64 in queue_job/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

queue_job/controllers/main.py#L61-L64

Added lines #L61 - L64 were not covered by tests
"%s, retry %d/%d in %.04f sec...",
errorcodes.lookup(err.pgcode),
tries,
DEPENDS_MAX_TRIES_ON_CONCURRENCY_FAILURE,
wait_time,
)
time.sleep(wait_time)

Check warning on line 71 in queue_job/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

queue_job/controllers/main.py#L71

Added line #L71 was not covered by tests
else:
break

Check warning on line 73 in queue_job/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

queue_job/controllers/main.py#L73

Added line #L73 was not covered by tests

@http.route("/queue_job/runjob", type="http", auth="none", save_session=False)
def runjob(self, db, job_uuid, **kw):
http.request.session.db = db
env = http.request.env(user=SUPERUSER_ID)

def retry_postpone(job, message, seconds=None):
job.env.clear()
with registry(job.env.cr.dbname).cursor() as new_cr:
job.env = api.Environment(new_cr, SUPERUSER_ID, {})
job.postpone(result=message, seconds=seconds)
job.set_pending(reset_retry=False)
job.store()

# ensure the job to run is in the correct state and lock the record
env.cr.execute(
"SELECT state FROM queue_job WHERE uuid=%s AND state=%s FOR UPDATE",
(job_uuid, ENQUEUED),
)
if not env.cr.fetchone():
_logger.warning(
"was requested to run job %s, but it does not exist, "
"or is not in state %s",
job_uuid,
ENQUEUED,
)
return ""

job = Job.load(env, job_uuid)
assert job and job.state == ENQUEUED

try:
try:
self._try_perform_job(env, job)
except OperationalError as err:
# Automatically retry the typical transaction serialization
# errors
if err.pgcode not in PG_CONCURRENCY_ERRORS_TO_RETRY:
raise

_logger.debug("%s OperationalError, postponed", job)
raise RetryableJobError(err.pgerror, seconds=PG_RETRY) from err

Check warning on line 115 in queue_job/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

queue_job/controllers/main.py#L115

Added line #L115 was not covered by tests

except RetryableJobError as err:
# delay the job later, requeue
retry_postpone(job, str(err), seconds=err.seconds)
_logger.debug("%s postponed", job)
# Do not trigger the error up because we don't want an exception
# traceback in the logs we should have the traceback when all
# retries are exhausted
env.cr.rollback()
return ""

Check warning on line 125 in queue_job/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

queue_job/controllers/main.py#L125

Added line #L125 was not covered by tests

except (FailedJobError, Exception) as orig_exception:

Check warning on line 127 in queue_job/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

queue_job/controllers/main.py#L127

Added line #L127 was not covered by tests
buff = StringIO()
traceback.print_exc(file=buff)
traceback_txt = buff.getvalue()
_logger.error(traceback_txt)

Check warning on line 131 in queue_job/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

queue_job/controllers/main.py#L130-L131

Added lines #L130 - L131 were not covered by tests
job.env.clear()
with registry(job.env.cr.dbname).cursor() as new_cr:
job.env = job.env(cr=new_cr)
vals = self._get_failure_values(job, traceback_txt, orig_exception)
job.set_failed(**vals)

Check warning on line 136 in queue_job/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

queue_job/controllers/main.py#L134-L136

Added lines #L134 - L136 were not covered by tests
job.store()
buff.close()
raise

_logger.debug("%s enqueue depends started", job)
self._enqueue_dependent_jobs(env, job)
_logger.debug("%s enqueue depends done", job)

Check warning on line 143 in queue_job/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

queue_job/controllers/main.py#L141-L143

Added lines #L141 - L143 were not covered by tests

return ""

def _get_failure_values(self, job, traceback_txt, orig_exception):
"""Collect relevant data from exception."""
exception_name = orig_exception.__class__.__name__

Check warning on line 149 in queue_job/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

queue_job/controllers/main.py#L149

Added line #L149 was not covered by tests
if hasattr(orig_exception, "__module__"):
exception_name = orig_exception.__module__ + "." + exception_name
exc_message = getattr(orig_exception, "name", str(orig_exception))
return {

Check warning on line 153 in queue_job/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

queue_job/controllers/main.py#L151-L153

Added lines #L151 - L153 were not covered by tests
"exc_info": traceback_txt,
"exc_name": exception_name,
"exc_message": exc_message,
}

# flake8: noqa: C901
@http.route("/queue_job/create_test_job", type="http", auth="user")
def create_test_job(
self,
priority=None,
max_retries=None,
channel=None,
description="Test job",
size=1,
failure_rate=0,
):
if not http.request.env.user.has_group("base.group_erp_manager"):
raise Forbidden(_("Access Denied"))

if failure_rate is not None:
try:
failure_rate = float(failure_rate)
except (ValueError, TypeError):
failure_rate = 0

Check warning on line 177 in queue_job/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

queue_job/controllers/main.py#L174-L177

Added lines #L174 - L177 were not covered by tests

if not (0 <= failure_rate <= 1):
raise BadRequest("failure_rate must be between 0 and 1")

Check warning on line 180 in queue_job/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

queue_job/controllers/main.py#L180

Added line #L180 was not covered by tests

if size is not None:
try:
size = int(size)
except (ValueError, TypeError):
size = 1

Check warning on line 186 in queue_job/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

queue_job/controllers/main.py#L183-L186

Added lines #L183 - L186 were not covered by tests

if priority is not None:
try:
priority = int(priority)
except ValueError:
priority = None

if max_retries is not None:
try:
max_retries = int(max_retries)
except ValueError:
max_retries = None

if size == 1:
return self._create_single_test_job(

Check warning on line 201 in queue_job/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

queue_job/controllers/main.py#L201

Added line #L201 was not covered by tests
priority=priority,
max_retries=max_retries,
channel=channel,
description=description,
failure_rate=failure_rate,
)

if size > 1:
return self._create_graph_test_jobs(

Check warning on line 210 in queue_job/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

queue_job/controllers/main.py#L210

Added line #L210 was not covered by tests
size,
priority=priority,
max_retries=max_retries,
channel=channel,
description=description,
failure_rate=failure_rate,
)
return ""

Check warning on line 218 in queue_job/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

queue_job/controllers/main.py#L218

Added line #L218 was not covered by tests

def _create_single_test_job(
self,
priority=None,
max_retries=None,
channel=None,
description="Test job",
size=1,
failure_rate=0,
):
delayed = (
http.request.env["queue.job"]
.with_delay(
priority=priority,
max_retries=max_retries,
channel=channel,
description=description,
)
._test_job(failure_rate=failure_rate)
)
return f"job uuid: {delayed.db_record().uuid}"

Check warning on line 239 in queue_job/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

queue_job/controllers/main.py#L239

Added line #L239 was not covered by tests

TEST_GRAPH_MAX_PER_GROUP = 5

def _create_graph_test_jobs(
self,
size,
priority=None,
max_retries=None,
channel=None,
description="Test job",
failure_rate=0,
):
model = http.request.env["queue.job"]
current_count = 0

Check warning on line 253 in queue_job/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

queue_job/controllers/main.py#L252-L253

Added lines #L252 - L253 were not covered by tests

possible_grouping_methods = (chain, group)

Check warning on line 255 in queue_job/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

queue_job/controllers/main.py#L255

Added line #L255 was not covered by tests

tails = [] # we can connect new graph chains/groups to tails
root_delayable = None

Check warning on line 258 in queue_job/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

queue_job/controllers/main.py#L257-L258

Added lines #L257 - L258 were not covered by tests
while current_count < size:
jobs_count = min(

Check warning on line 260 in queue_job/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

queue_job/controllers/main.py#L260

Added line #L260 was not covered by tests
size - current_count, random.randint(1, self.TEST_GRAPH_MAX_PER_GROUP)
)

jobs = []

Check warning on line 264 in queue_job/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

queue_job/controllers/main.py#L264

Added line #L264 was not covered by tests
for __ in range(jobs_count):
current_count += 1
jobs.append(

Check warning on line 267 in queue_job/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

queue_job/controllers/main.py#L266-L267

Added lines #L266 - L267 were not covered by tests
model.delayable(
priority=priority,
max_retries=max_retries,
channel=channel,
description="%s #%d" % (description, current_count),
)._test_job(failure_rate=failure_rate)
)

grouping = random.choice(possible_grouping_methods)
delayable = grouping(*jobs)

Check warning on line 277 in queue_job/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

queue_job/controllers/main.py#L276-L277

Added lines #L276 - L277 were not covered by tests
if not root_delayable:
root_delayable = delayable

Check warning on line 279 in queue_job/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

queue_job/controllers/main.py#L279

Added line #L279 was not covered by tests
else:
tail_delayable = random.choice(tails)
tail_delayable.on_done(delayable)
tails.append(delayable)

Check warning on line 283 in queue_job/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

queue_job/controllers/main.py#L281-L283

Added lines #L281 - L283 were not covered by tests

root_delayable.delay()

Check warning on line 285 in queue_job/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

queue_job/controllers/main.py#L285

Added line #L285 was not covered by tests

return (

Check warning on line 287 in queue_job/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

queue_job/controllers/main.py#L287

Added line #L287 was not covered by tests
f"graph uuid: {list(root_delayable._head())[0]._generated_job.graph_uuid}"
)
34 changes: 34 additions & 0 deletions queue_job/data/queue_data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<data noupdate="1">
<record id="ir_cron_queue_job_garbage_collector" model="ir.cron">
<field name="name">Jobs Garbage Collector</field>
<field name="interval_number">5</field>
<field name="interval_type">minutes</field>
<field ref="model_queue_job" name="model_id" />
<field name="state">code</field>
<field name="code">model.requeue_stuck_jobs()</field>
</record>
<!-- Queue-job-related subtypes for messaging / Chatter -->
<record id="mt_job_failed" model="mail.message.subtype">
<field name="name">Job failed</field>
<field name="res_model">queue.job</field>
<field name="default" eval="True" />
</record>
<record id="ir_cron_autovacuum_queue_jobs" model="ir.cron">
<field name="name">AutoVacuum Job Queue</field>
<field ref="model_queue_job" name="model_id" />
<field eval="True" name="active" />
<field name="user_id" ref="base.user_root" />
<field name="interval_number">1</field>
<field name="interval_type">days</field>
<field name="state">code</field>
<field name="code">model.autovacuum()</field>
</record>
</data>
<data noupdate="0">
<record model="queue.job.channel" id="channel_root">
<field name="name">root</field>
</record>
</data>
</odoo>
6 changes: 6 additions & 0 deletions queue_job/data/queue_job_function_data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<odoo noupdate="1">
<record id="job_function_queue_job__test_job" model="queue.job.function">
<field name="model_id" ref="queue_job.model_queue_job" />
<field name="method">_test_job</field>
</record>
</odoo>
Loading
Loading