Browse Source

Make sure Check.last_ping and Ping.created timestamps match exactly

pull/325/head
Pēteris Caune 5 years ago
parent
commit
77033760f9
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
4 changed files with 27 additions and 3 deletions
  1. +1
    -0
      CHANGELOG.md
  2. +19
    -0
      hc/api/migrations/0069_auto_20200117_1227.py
  3. +6
    -3
      hc/api/models.py
  4. +1
    -0
      hc/api/tests/test_ping.py

+ 1
- 0
CHANGELOG.md View File

@ -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
- 0
hc/api/migrations/0069_auto_20200117_1227.py View 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),
),
]

+ 6
- 3
hc/api/models.py View File

@ -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)


+ 1
- 0
hc/api/tests/test_ping.py View File

@ -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…
Cancel
Save