Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trying to fix #151 #348

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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