Skip to content

Commit

Permalink
[FIX] Respect cron.user_id for manually triggered queue jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
codingforfun authored and fshah-initos committed Apr 5, 2021
1 parent e32d843 commit dca7862
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 12 deletions.
1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ exclude: |
# NOT INSTALLABLE ADDONS
^base_export_async/|
^base_import_async/|
^queue_job_cron/|
^queue_job_subscribe/|
^test_base_import_async/|
# END NOT INSTALLABLE ADDONS
Expand Down
2 changes: 1 addition & 1 deletion queue_job/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from . import models
from . import wizards
from . import jobrunner
from .hooks.post_init_hook import post_init_hook
from .post_init_hook import post_init_hook

# shortcuts
from .job import identity_exact
1 change: 0 additions & 1 deletion queue_job/models/queue_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,6 @@ def autovacuum(self):
)
if jobs:
jobs.unlink()
self.env.cr.commit()
else:
break
return True
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion queue_job/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import mock

from odoo.addons.queue_job.job import Job
from ..job import Job


class JobCounter:
Expand Down
21 changes: 13 additions & 8 deletions queue_job_cron/models/ir_cron.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,19 @@ def _run_job_as_queue_job(self, server_action):
return server_action.run()

def method_direct_trigger(self):
if self.run_as_queue_job:
return self.with_delay(
priority=self.priority,
description=self.name,
channel=self.channel_id.complete_name,
)._run_job_as_queue_job(server_action=self.ir_actions_server_id)
else:
return super().method_direct_trigger()
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)
Expand Down
1 change: 1 addition & 0 deletions setup/queue_job_cron/odoo/addons/queue_job_cron
6 changes: 6 additions & 0 deletions setup/queue_job_cron/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)

0 comments on commit dca7862

Please sign in to comment.