From 770d768fd3bbb9a4232af36810388cc34cbcfb57 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?R=C3=A9mi=20-=20Le=20Filament?= <remi@le-filament.com>
Date: Mon, 11 Apr 2022 18:17:44 +0200
Subject: [PATCH] [ADD] variable to force multiprocessing

---
 README.md              | 4 ++++
 templates/odoo.conf.j2 | 2 +-
 templates/prod.yaml.j2 | 2 +-
 templates/test.yaml.j2 | 6 ++++--
 4 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/README.md b/README.md
index 0d0841e..5ae8c79 100644
--- a/README.md
+++ b/README.md
@@ -51,6 +51,8 @@ odoo_prod_example: # To be renamed odoo_prod
     db_pass: "odooDbPasswordToBeModified"
     # PROD Database name
     db: "odoo"
+    ## OPTIONAL - use this variable to force using multiprocessing iso multithreading
+    # force_odoo_workers: True
     ## OPTIONAL - only needed if no nonprod_instances are defined
     ## Custom modules Le Filament (one module per repo)
     # custom_modules:
@@ -124,6 +126,8 @@ odoo_nonprod_instances_example: # To be renamed odoo_nonprod_instances
       db: "odoo_test"
       ## Tag that will be used on the built test Docker image
       image_version: "{{ odoo_version }}_test"
+      ## OPTIONAL - use this variable to force using multiprocessing iso multithreading
+      # force_odoo_workers: True
       ## Custom modules Le Filament (one module per repo)
       custom_modules:
           - automatic_bank_statement_import
diff --git a/templates/odoo.conf.j2 b/templates/odoo.conf.j2
index 33cdfa7..1358a27 100644
--- a/templates/odoo.conf.j2
+++ b/templates/odoo.conf.j2
@@ -49,7 +49,7 @@ smtp_server = smtp
 ; smtp_user = False
 unaccent = True
 without_demo = all
-{% if ansible_processor_vcpus > 2 %}
+{% if ansible_processor_vcpus > 2 or odoo_prod.force_odoo_workers is defined %}
 workers = {{ (ansible_processor_vcpus * 2 - 1) | int | abs }}
 max_cron_threads = {{ ansible_processor_vcpus | int }}
 {% else %}
diff --git a/templates/prod.yaml.j2 b/templates/prod.yaml.j2
index e205cc0..54db4c6 100644
--- a/templates/prod.yaml.j2
+++ b/templates/prod.yaml.j2
@@ -45,7 +45,7 @@ services:
             co.elastic.logs/multiline.negate: 'true'
             co.elastic.logs/multiline.match: "after"
             traefik.enable: "true"
-{% if ansible_processor_vcpus > 2 %}
+{% if ansible_processor_vcpus > 2 or odoo_prod.force_odoo_workers is defined %}
             traefik.http.routers.odoo-longpolling.rule: "Host(`{{ odoo_prod.url }}`{% if odoo_prod.url2 is defined %}, `{{ odoo_prod.url2 }}`{% endif %}) && PathPrefix(`/longpolling/`)"
             traefik.http.routers.odoo-longpolling.service: "odoo-longpolling"
             traefik.http.services.odoo-longpolling.loadbalancer.server.port: "8072"
diff --git a/templates/test.yaml.j2 b/templates/test.yaml.j2
index 0076e9a..8f17639 100644
--- a/templates/test.yaml.j2
+++ b/templates/test.yaml.j2
@@ -35,7 +35,7 @@ services:
         labels:
             co.elastic.logs/enabled: "false"
             traefik.enable: "true"
-{% if ansible_processor_vcpus > 2 %}
+{% if ansible_processor_vcpus > 2 or item.force_odoo_workers is defined %}
             traefik.http.routers.{{ item.dir }}-longpolling.rule: "Host(`{{ item.url }}`) && PathPrefix(`/longpolling/`)"
             traefik.http.routers.{{ item.dir }}-longpolling.service: "{{ item.dir }}-longpolling"
             traefik.http.services.{{ item.dir }}-longpolling.loadbalancer.server.port: "8072"
@@ -52,9 +52,11 @@ services:
             - --smtp-port=1025
             - --database={{ item.db }}
             - --init=web_environment_ribbon
-{% if ansible_processor_vcpus > 2 %}
+{% if ansible_processor_vcpus > 2 or item.force_odoo_workers is defined %}
             - --workers=2
             - --max-cron-threads=1
+{% elif odoo_prod.force_odoo_workers is defined %}
+            - --workers=0
 {% endif %}
 
     db:
-- 
GitLab