Merge pull request #976 from jainnikhil30/scale_callback_receiver_workers

configure callback receiver workers based on CPU
This commit is contained in:
Elijah DeLee
2022-08-09 07:23:08 -04:00
committed by GitHub
2 changed files with 38 additions and 2 deletions

View File

@@ -0,0 +1,27 @@
# Copyright (c) 2017 Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from ansible.errors import AnsibleFilterError
__ERROR_MSG = "Not a valid cpu value. Cannot process value"
class FilterModule(object):
def filters(self):
return {
'cpu_string_to_decimal': self.cpu_string_to_decimal
}
def cpu_string_to_decimal(self, cpu_string):
# verify if task_output is a dict
if not isinstance(cpu_string, str):
raise AnsibleFilterError(__ERROR_MSG)
if cpu_string[-1] == 'm':
cpu = int(cpu_string[:-1])//1000
else:
cpu = int(cpu_string)
return cpu

View File

@@ -42,10 +42,19 @@ data:
SYSTEM_TASK_ABS_CPU = '{{ task_resource_requirements["limits"]["cpu"] }}'
{% endif %}
{%- set cpu_limit = task_resource_requirements["limits"]["cpu"] if "limits" in task_resource_requirements and "cpu" in task_resource_requirements["limits"] -%}
{%- if cpu_limit is defined -%}
{%- set callback_receiver_cpu = cpu_limit | cpu_string_to_decimal -%}
{%- if callback_receiver_cpu |int > 4 -%}
# Set callback receiver workers based off cpu limit, default workers are 4, but if we have more than 4 cpu we can set higher value for workers
JOB_EVENT_WORKERS = {{ callback_receiver_cpu }}
{%- endif -%}
{%- endif %}
SECRET_KEY = get_secret()
ALLOWED_HOSTS = ['*']
INTERNAL_API_URL = 'http://127.0.0.1:8052'
# Sets Ansible Collection path