Skip to content

Commit

Permalink
Trying to fix globocom#151
Browse files Browse the repository at this point in the history
  • Loading branch information
brunojuliao committed Oct 27, 2021
1 parent 9ab53f8 commit 2d011c5
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions networkapi/healthcheckexpect/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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')
Expand All @@ -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

0 comments on commit 2d011c5

Please sign in to comment.