常见的技术问题

“计划的操作不会在预期的确切时间运行`

在 Odoo.sh 平台上,我们无法保证计划操作的确切运行时间。

这是因为同一台服务器上可能有多个客户,我们必须保证每个客户都有公平的服务器份额。因此,计划操作的实现方式与在常规 Odoo 服务器上略有不同,并且按照 尽力而为 策略运行。

警告

不要期望任何计划的操作运行频率高于每 5 分钟一次。

是否有关于计划操作的“最佳实践”?

**Odoo.sh 总是限制计划操作(aka crons)的执行时间 **此,在开发自己的克隆时,您必须牢记这一事实。

我们建议:

  • 计划的操作应该适用于小批量记录。

  • 您计划的行动应该在处理每个批次后提交他们的工作;这样,如果他们被时间限制打断,就没有必要重新开始。

  • 您计划的操作应该是“幂等<https://stackoverflow.com/a/1077421/3332416>”_:如果它们开始的频率高于预期,则它们不得引起副作用。

How can I automate tasks when an IP address change occurs?

Odoo.sh notifies project administrators of IP address changes. Additionally, when the IP address of a production instance changes, an HTTP GET request is made to the path /_odoo.sh/ip-change with the new IP address included as a query string parameter (new), along with the previous IP address as an additional parameter (old).

This mechanism allows custom actions to be applied in response to the IP address change (e.g., sending an email, contacting a firewall API, configuring database objects, etc.)

For security reasons, the /_odoo.sh/ip-change route is accessible only internally by the platform itself and returns a 403 response if accessed through any other means.

Here is a pseudo-implementation example:

class IPChangeController(http.Controller):

    @http.route('/_odoo.sh/ip-change', auth='public')
    def ip_change(self, old=None, new=None):
        _logger.info("IP address changed from %s to %s", old, new)
        # Then perform whatever action required for your use case, e.g., update an
        # ir.config_parameter, send an email, contact an external firewall service's API, ...
        return 'ok'