From 2d011c548917c39c59e88cd0d334060c649405dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bruno=20Oliveira=20Juli=C3=A3o?= <2057387+brunojuliao@users.noreply.github.com> Date: Wed, 27 Oct 2021 17:59:54 -0300 Subject: [PATCH] Trying to fix #151 --- networkapi/healthcheckexpect/models.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/networkapi/healthcheckexpect/models.py b/networkapi/healthcheckexpect/models.py index e92befa27..6d7f98ab8 100644 --- a/networkapi/healthcheckexpect/models.py +++ b/networkapi/healthcheckexpect/models.py @@ -14,6 +14,7 @@ # See the License for the specific language governing permissions and # limitations under the License. import logging +import threading from django.core.exceptions import ObjectDoesNotExist from django.db import models @@ -181,6 +182,7 @@ def insert_expect_string(self, authenticated_user, expect_string, ambiente=None) raise HealthcheckExpectError( e, u'Falha ao inserir healthcheck_expect.') +lock = threading.Lock() class Healthcheck(BaseModel): id = models.AutoField(primary_key=True, db_column='id_healthcheck') @@ -197,10 +199,11 @@ class Meta(BaseModel.Meta): managed = True def get_create_healthcheck(self, healthcheck): - try: - hc = Healthcheck.objects.get(**healthcheck) - except ObjectDoesNotExist: - hc = Healthcheck(**healthcheck) - hc.save() + with lock: + try: + hc = Healthcheck.objects.get(**healthcheck) + except ObjectDoesNotExist: + hc = Healthcheck(**healthcheck) + hc.save() return hc