Skip to content

Commit

Permalink
Update workflows and enhance queue job functionality
Browse files Browse the repository at this point in the history
Updated GitHub Actions to use the latest versions of actions and enhanced queue job functionality with a new `_cron_trigger` method, improving scheduled task handling. Incremented the module version to reflect these changes.
  • Loading branch information
dhongu committed Feb 5, 2025
1 parent 740f4c8 commit 60db8d5
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 20 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ jobs:
pre-commit:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v2
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Get python version
run: echo "PY=$(python -VV | sha256sum | cut -d' ' -f1)" >> $GITHUB_ENV
- uses: actions/cache@v1
- uses: actions/cache@v4
with:
path: ~/.cache/pre-commit
key: pre-commit|${{ env.PY }}|${{ hashFiles('.pre-commit-config.yaml') }}
Expand Down
11 changes: 6 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-latest
name: Detect unreleased dependencies
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- run: |
for reqfile in requirements.txt test-requirements.txt ; do
if [ -f ${reqfile} ] ; then
Expand Down Expand Up @@ -50,7 +50,7 @@ jobs:
ports:
- 5432:5432
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
persist-credentials: false
- name: Install addons and dependencies
Expand All @@ -68,8 +68,9 @@ jobs:
run: oca_init_test_database
- name: Run tests
run: oca_run_tests
- uses: codecov/codecov-action@v1
- uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
# - name: Update .pot files
# run: oca_export_and_push_pot https://x-access-token:${{ secrets.GIT_PUSH_TOKEN }}@github.com/${{ github.repository }}
# if: ${{ matrix.makepot == 'true' && github.event_name == 'push' && github.repository_owner == 'dhongu' }}

# if: ${{ matrix.makepot == 'true' && github.event_name == 'push' && github.repository_owner == 'OCA' }}
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": "16.0.1.0.2",
"version": "16.0.1.0.3",
"license": "AGPL-3",
"website": "https://www.terrabit.ro",
"category": "Others",
Expand Down
31 changes: 20 additions & 11 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 All @@ -42,7 +35,7 @@ def _job_runner(self, commit=True):
if limit_jobs:
limit_jobs = int(limit_jobs)
else:
limit_jobs = 10
limit_jobs = 100

job_count = 0
while job:
Expand All @@ -52,4 +45,20 @@ def _job_runner(self, commit=True):
if job_count >= limit_jobs:
if job:
job._ensure_cron_trigger()
job._cron_trigger()
break
_logger.info("Job runner finished")

@api.model
def _cron_trigger(self, at=None):
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 60db8d5

Please sign in to comment.