Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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