Skip to content

Commit

Permalink
[FIX] queue_job: enhance CRON trigger functionality and logging
Browse files Browse the repository at this point in the history
  • Loading branch information
dhongu committed Feb 4, 2025
1 parent 138dc9f commit e19af05
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion deltatech_queue_job/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"name": "Deltatech Queue Job Enhancements",
"summary": "Deltatech Queue Job",
"author": "Terrabit, Dorin Hongu",
"version": "17.0.1.0.2",
"version": "17.0.1.0.3",
"license": "AGPL-3",
"website": "https://www.terrabit.ro",
"category": "Others",
Expand Down
26 changes: 14 additions & 12 deletions deltatech_queue_job/models/queue_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,16 @@
# See README.rst file on addons root folder for license details
import logging

from odoo import _, api, models

from odoo import _, api,fields, models
from datetime import timedelta
_logger = logging.getLogger(__name__)


class QueueJob(models.Model):
_inherit = "queue.job"

def start_cron_trigger(self):
_logger.info("Starting CRON trigger")
domain = [("queue_job_runner", "=", True)]
crons = self.env["ir.cron"].sudo().with_context(active_test=False).search(domain)
for cron in crons:
cron.active = True
_logger.info("Starting CRON trigger for %s", cron.name)
cron._trigger()

self._cron_trigger()
return {
"type": "ir.actions.client",
"tag": "display_notification",
Expand Down Expand Up @@ -58,5 +51,14 @@ def _job_runner(self, commit=True):

@api.model
def _cron_trigger(self, at=None):
_logger.info("CRON Trigger")
return super()._cron_trigger(at=at)
domain = [("queue_job_runner", "=", True)]
crons = self.env["ir.cron"].sudo().with_context(active_test=False).search(domain)
for cron in crons:
cron.active = True
trigger = self.env["ir.cron.trigger"].search([("cron_id", "=", cron.id)])
if trigger:
trigger.unlink()
if not at:
at = fields.Datetime.now() + timedelta(seconds=5)
cron._trigger(at=at)
_logger.info("CRON trigger for %s at %s", (cron.name, at))

0 comments on commit e19af05

Please sign in to comment.