forked from GithubBackups/healthchecks
Make sure Check.last_ping and Ping.created timestamps match exactly
This commit is contained in:
parent
58a118c494
commit
77033760f9
@ -11,6 +11,7 @@ All notable changes to this project will be documented in this file.
|
|||||||
|
|
||||||
### Bug Fixes
|
### Bug Fixes
|
||||||
- Increase the allowable length of Matrix room alias to 100 (#320)
|
- Increase the allowable length of Matrix room alias to 100 (#320)
|
||||||
|
- Make sure Check.last_ping and Ping.created timestamps match exactly
|
||||||
|
|
||||||
|
|
||||||
## v1.12.0 - 2020-01-02
|
## v1.12.0 - 2020-01-02
|
||||||
|
19
hc/api/migrations/0069_auto_20200117_1227.py
Normal file
19
hc/api/migrations/0069_auto_20200117_1227.py
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
# Generated by Django 3.0.1 on 2020-01-17 12:27
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.utils.timezone
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('api', '0068_auto_20200117_1023'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='ping',
|
||||||
|
name='created',
|
||||||
|
field=models.DateTimeField(default=django.utils.timezone.now),
|
||||||
|
),
|
||||||
|
]
|
@ -236,13 +236,15 @@ class Check(models.Model):
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
def ping(self, remote_addr, scheme, method, ua, body, action):
|
def ping(self, remote_addr, scheme, method, ua, body, action):
|
||||||
|
now = timezone.now()
|
||||||
|
|
||||||
if action == "start":
|
if action == "start":
|
||||||
self.last_start = timezone.now()
|
self.last_start = now
|
||||||
# Don't update "last_ping" field.
|
# Don't update "last_ping" field.
|
||||||
elif action == "ign":
|
elif action == "ign":
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
self.last_ping = timezone.now()
|
self.last_ping = now
|
||||||
if self.last_start:
|
if self.last_start:
|
||||||
self.last_duration = self.last_ping - self.last_start
|
self.last_duration = self.last_ping - self.last_start
|
||||||
self.last_start = None
|
self.last_start = None
|
||||||
@ -267,6 +269,7 @@ class Check(models.Model):
|
|||||||
|
|
||||||
ping = Ping(owner=self)
|
ping = Ping(owner=self)
|
||||||
ping.n = self.n_pings
|
ping.n = self.n_pings
|
||||||
|
ping.created = now
|
||||||
if action in ("start", "fail", "ign"):
|
if action in ("start", "fail", "ign"):
|
||||||
ping.kind = action
|
ping.kind = action
|
||||||
|
|
||||||
@ -321,7 +324,7 @@ class Ping(models.Model):
|
|||||||
id = models.BigAutoField(primary_key=True)
|
id = models.BigAutoField(primary_key=True)
|
||||||
n = models.IntegerField(null=True)
|
n = models.IntegerField(null=True)
|
||||||
owner = models.ForeignKey(Check, models.CASCADE)
|
owner = models.ForeignKey(Check, models.CASCADE)
|
||||||
created = models.DateTimeField(auto_now_add=True)
|
created = models.DateTimeField(default=timezone.now)
|
||||||
kind = models.CharField(max_length=6, blank=True, null=True)
|
kind = models.CharField(max_length=6, blank=True, null=True)
|
||||||
scheme = models.CharField(max_length=10, default="http")
|
scheme = models.CharField(max_length=10, default="http")
|
||||||
remote_addr = models.GenericIPAddressField(blank=True, null=True)
|
remote_addr = models.GenericIPAddressField(blank=True, null=True)
|
||||||
|
@ -25,6 +25,7 @@ class PingTestCase(BaseTestCase):
|
|||||||
ping = Ping.objects.latest("id")
|
ping = Ping.objects.latest("id")
|
||||||
self.assertEqual(ping.scheme, "http")
|
self.assertEqual(ping.scheme, "http")
|
||||||
self.assertEqual(ping.kind, None)
|
self.assertEqual(ping.kind, None)
|
||||||
|
self.assertEqual(ping.created, self.check.last_ping)
|
||||||
|
|
||||||
def test_it_changes_status_of_paused_check(self):
|
def test_it_changes_status_of_paused_check(self):
|
||||||
self.check.status = "paused"
|
self.check.status = "paused"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user