From 762547c1f53a0dd5032e9feb4011ebde926749a6 Mon Sep 17 00:00:00 2001 From: git_admin Date: Mon, 27 Apr 2026 08:44:42 +0000 Subject: [PATCH] Tower: upload cetmix_tower_server_queue 16.0.1.2.2 (via marketplace) --- .../models/cx_tower_server.py | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 addons/cetmix_tower_server_queue/models/cx_tower_server.py diff --git a/addons/cetmix_tower_server_queue/models/cx_tower_server.py b/addons/cetmix_tower_server_queue/models/cx_tower_server.py new file mode 100644 index 0000000..7e84b25 --- /dev/null +++ b/addons/cetmix_tower_server_queue/models/cx_tower_server.py @@ -0,0 +1,77 @@ +# Copyright (C) 2022 Cetmix OÜ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from odoo import models + + +class CxTowerServer(models.Model): + _inherit = "cx.tower.server" + + def _command_runner_wrapper( + self, + command, + log_record, + rendered_command_code, + sudo=None, + rendered_command_path=None, + ssh_connection=None, + **kwargs, + ): + # If the flight plan log has an entry on the parent flight plan log, + # it means that this flight plan was launched from another plan, + # this plan should be launched as a synchronous command to + # preserve the order of execution of commands with action “Run flight plan”. + # Use runner only if command log record is provided. + if log_record and not log_record.plan_log_id.parent_flight_plan_log_id: + job = self.with_delay()._queue_command_runner_wrapper( + command=command, + log_record=log_record, + rendered_command_code=rendered_command_code, + sudo=sudo, + rendered_command_path=rendered_command_path, + ssh_connection=ssh_connection, + **kwargs, + ) + log_record.sudo().queue_job_id = job.db_record().id + + # Otherwise fallback to `super` to return the command output + else: + return super()._command_runner_wrapper( + command=command, + log_record=log_record, + rendered_command_code=rendered_command_code, + sudo=sudo, + rendered_command_path=rendered_command_path, + ssh_connection=ssh_connection, + **kwargs, + ) + + def _queue_command_runner_wrapper( + self, + command, + log_record, + rendered_command_code, + sudo=None, + rendered_command_path=None, + ssh_connection=None, + **kwargs, + ): + # avoid executing command if plan was stopped + log_record.invalidate_recordset(["plan_log_id"]) + plan_log_id = log_record.plan_log_id + if plan_log_id: + plan_log_id.invalidate_recordset(["is_stopped"]) + + # If plan was stopped, stop the command + if plan_log_id.is_stopped: + log_record.stop() + return + + return self._command_runner( + command=command, + log_record=log_record, + rendered_command_code=rendered_command_code, + sudo=sudo, + rendered_command_path=rendered_command_path, + ssh_connection=ssh_connection, + **kwargs, + )