]> git.0d.be Git - earwig.git/commitdiff
track last check in a dedicated model field
authorFrédéric Péters <fpeters@0d.be>
Sun, 2 Sep 2018 07:11:38 +0000 (09:11 +0200)
committerFrédéric Péters <fpeters@0d.be>
Sun, 2 Sep 2018 10:12:23 +0000 (12:12 +0200)
earwig/sounds/management/commands/update_sounds.py
earwig/sounds/migrations/0004_channel_last_check_timestamp.py [new file with mode: 0644]
earwig/sounds/models.py

index 306731a25e5475910c8171e0c0dfbfb794b6c727..31722bc53d20bf23b08dbc3407a325ecca34a292 100644 (file)
@@ -36,10 +36,12 @@ class Command(BaseCommand):
             qs = qs.filter(Q(title__icontains=options.get('channel')) |
                            Q(channel_url__icontains=options.get('channel')))
         if options.get('delay'):
-            qs = qs.filter(last_update_timestamp__lt=now() -
-                    datetime.timedelta(seconds=options.get('delay')))
+            qs = qs.filter(Q(last_check_timestamp__isnull=True) |
+                           Q(last_check_timestamp__lt=now() -
+                             datetime.timedelta(seconds=options.get('delay'))))
         for channel in qs:
             if options.get('verbosity'):
                 sys.stderr.write('Updating %s\n' % channel)
             channel.update()
-            channel.save()
+            channel.last_check_timestamp = now()
+            channel.save(update_fields=['last_check_timestamp'])
diff --git a/earwig/sounds/migrations/0004_channel_last_check_timestamp.py b/earwig/sounds/migrations/0004_channel_last_check_timestamp.py
new file mode 100644 (file)
index 0000000..e50de88
--- /dev/null
@@ -0,0 +1,20 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.11.11 on 2018-09-02 07:08
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('sounds', '0003_auto_20180901_1745'),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name='channel',
+            name='last_check_timestamp',
+            field=models.DateTimeField(null=True),
+        ),
+    ]
index 1ea8f46501299525dae13d2a76ff997c748668fe..80a6df6afc7d40b67f8a881394b894de712ccdaa 100644 (file)
@@ -43,6 +43,7 @@ class Channel(models.Model):
 
     creation_timestamp = models.DateTimeField(auto_now_add=True)
     last_update_timestamp = models.DateTimeField(auto_now=True)
+    last_check_timestamp = models.DateTimeField(null=True)
 
     class Meta:
         ordering = ('title',)