常见技术问题

“定时任务不能在预期的确切时间运行”

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

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

警告

不要期望任何计划动作运行的频率超过每5分钟一次。

关于定时操作,有没有“最佳实践”?

Odoo.sh always limits the execution time of scheduled actions (*aka* crons). Therefore, you must keep this fact in mind when developing your own crons.

我们建议:

  • 您的定时操作应该处理小批量的记录。

  • 您的定时操作应该在处理每个批次后提交它们的工作;这样,如果它们被时间限制中断,就不需要重新开始。

  • 您的定时操作应该是 幂等的 :如果它们比预期更频繁地启动,它们不应该引起副作用。

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'