Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion .oca/oca-port/blacklist/queue_job.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"440": "Already fixed",
"466": "Reverting #387",
"511": "Icon already updated for v16",
"537": "Already ported"
"537": "Already ported",
"OCA/queue#658": "(auto) Nothing to port from PR #658"
}
}
2 changes: 1 addition & 1 deletion queue_job/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ be customized in ``Base._job_prepare_context_before_enqueue_keys``.
When you are developing (ie: connector modules) you might want
to bypass the queue job and run your code immediately.

To do so you can set `QUEUE_JOB__NO_DELAY=1` in your enviroment.
To do so you can set `QUEUE_JOB__NO_DELAY=1` in your environment.

**Bypass jobs in tests**

Expand Down
12 changes: 10 additions & 2 deletions queue_job/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,8 +539,8 @@ def perform(self):

return self.result

def enqueue_waiting(self):
sql = """
def _get_common_dependent_jobs_query(self):
return """
UPDATE queue_job
SET state = %s
FROM (
Expand Down Expand Up @@ -568,9 +568,17 @@ def enqueue_waiting(self):
AND %s = ALL(jobs.parent_states)
AND state = %s;
"""

def enqueue_waiting(self):
sql = self._get_common_dependent_jobs_query()
self.env.cr.execute(sql, (PENDING, self.uuid, DONE, WAIT_DEPENDENCIES))
self.env["queue.job"].invalidate_model(["state"])

def cancel_dependent_jobs(self):
sql = self._get_common_dependent_jobs_query()
self.env.cr.execute(sql, (CANCELLED, self.uuid, CANCELLED, WAIT_DEPENDENCIES))
self.env["queue.job"].invalidate_cache(["state"])

def store(self):
"""Store the Job"""
job_model = self.env["queue.job"]
Expand Down
2 changes: 2 additions & 0 deletions queue_job/models/queue_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,8 @@ def _change_job_state(self, state, result=None):
elif state == CANCELLED:
job_.set_cancelled(result=result)
job_.store()
record.env["queue.job"].flush()
job_.cancel_dependent_jobs()
else:
raise ValueError("State not supported: %s" % state)

Expand Down
2 changes: 1 addition & 1 deletion queue_job/readme/USAGE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ be customized in ``Base._job_prepare_context_before_enqueue_keys``.
When you are developing (ie: connector modules) you might want
to bypass the queue job and run your code immediately.

To do so you can set `QUEUE_JOB__NO_DELAY=1` in your enviroment.
To do so you can set `QUEUE_JOB__NO_DELAY=1` in your environment.

**Bypass jobs in tests**

Expand Down
2 changes: 1 addition & 1 deletion queue_job/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,7 @@ <h3><a class="toc-backref" href="#toc-entry-7">Configure default options for job
<strong>Bypass jobs on running Odoo</strong></p>
<p>When you are developing (ie: connector modules) you might want
to bypass the queue job and run your code immediately.</p>
<p>To do so you can set <cite>QUEUE_JOB__NO_DELAY=1</cite> in your enviroment.</p>
<p>To do so you can set <cite>QUEUE_JOB__NO_DELAY=1</cite> in your environment.</p>
<p><strong>Bypass jobs in tests</strong></p>
<p>When writing tests on job-related methods is always tricky to deal with
delayed recordsets. To make your testing life easier
Expand Down
21 changes: 21 additions & 0 deletions queue_job/views/queue_job_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,22 @@
string="Cancelled"
domain="[('state', '=', 'cancelled')]"
/>
<separator />
<filter
name="last_24_hours"
string="Last 24 hours"
domain="[('date_created', '&gt;=', (context_today() - datetime.timedelta(days=1)).strftime('%Y-%m-%d'))]"
/>
<filter
name="last_7_days"
string="Last 7 days"
domain="[('date_created', '&gt;=', (context_today() - datetime.timedelta(days=7)).strftime('%Y-%m-%d'))]"
/>
<filter
name="last_30_days"
string="Last 30 days"
domain="[('date_created', '&gt;=', (context_today() - datetime.timedelta(days=30)).strftime('%Y-%m-%d'))]"
/>
<group expand="0" string="Group By">
<filter
name="group_by_channel"
Expand Down Expand Up @@ -286,6 +302,11 @@
string="Graph"
context="{'group_by': 'graph_uuid'}"
/>
<filter
name="group_by_date_created"
string="Created date"
context="{'group_by': 'date_created'}"
/>
</group>
</search>
</field>
Expand Down
37 changes: 37 additions & 0 deletions test_queue_job/tests/test_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
RetryableJobError,
)
from odoo.addons.queue_job.job import (
CANCELLED,
DONE,
ENQUEUED,
FAILED,
Expand Down Expand Up @@ -489,6 +490,42 @@ def test_button_done(self):
stored.result, "Manually set to done by %s" % self.env.user.name
)

def test_button_done_enqueue_waiting_dependencies(self):
job_root = Job(self.env["test.queue.job"].testing_method)
job_child = Job(self.env["test.queue.job"].testing_method)
job_child.add_depends({job_root})

DelayableGraph._ensure_same_graph_uuid([job_root, job_child])
job_root.store()
job_child.store()

self.assertEqual(job_child.state, WAIT_DEPENDENCIES)
record_root = job_root.db_record()
record_child = job_child.db_record()
# Trigger button done
record_root.button_done()
# Check the state
self.assertEqual(record_root.state, DONE)
self.assertEqual(record_child.state, PENDING)

def test_button_cancel_dependencies(self):
job_root = Job(self.env["test.queue.job"].testing_method)
job_child = Job(self.env["test.queue.job"].testing_method)
job_child.add_depends({job_root})

DelayableGraph._ensure_same_graph_uuid([job_root, job_child])
job_root.store()
job_child.store()

self.assertEqual(job_child.state, WAIT_DEPENDENCIES)
record_root = job_root.db_record()
record_child = job_child.db_record()
# Trigger button cancelled
record_root.button_cancelled()
# Check the state
self.assertEqual(record_root.state, CANCELLED)
self.assertEqual(record_child.state, CANCELLED)

def test_requeue(self):
stored = self._create_job()
stored.write({"state": "failed"})
Expand Down
Loading