forked from GithubBackups/healthchecks
fillnpings catches up with pings received during the execution of the command
This commit is contained in:
parent
b592e5b449
commit
68fe11a41b
@ -47,21 +47,26 @@ class Command(BaseCommand):
|
|||||||
last_pk = Ping.objects.order_by('-pk')[0].pk
|
last_pk = Ping.objects.order_by('-pk')[0].pk
|
||||||
queryset = Ping.objects.order_by('pk')
|
queryset = Ping.objects.order_by('pk')
|
||||||
|
|
||||||
transaction.set_autocommit(False)
|
|
||||||
while pk < last_pk:
|
while pk < last_pk:
|
||||||
for ping in queryset.filter(pk__gt=pk)[:chunksize]:
|
transaction.set_autocommit(False)
|
||||||
pk = ping.pk
|
while pk < last_pk:
|
||||||
counts[ping.owner_id] += 1
|
for ping in queryset.filter(pk__gt=pk)[:chunksize]:
|
||||||
|
pk = ping.pk
|
||||||
|
counts[ping.owner_id] += 1
|
||||||
|
|
||||||
ping.n = counts[ping.owner_id]
|
ping.n = counts[ping.owner_id]
|
||||||
ping.save(update_fields=("n", ))
|
ping.save(update_fields=("n", ))
|
||||||
|
|
||||||
gc.collect()
|
gc.collect()
|
||||||
progress = 100 * pk / last_pk
|
progress = 100 * pk / last_pk
|
||||||
self.stdout.write("Processed ping id %d (%.2f%%)" % (pk, progress))
|
self.stdout.write(
|
||||||
|
"Processed ping id %d (%.2f%%)" % (pk, progress))
|
||||||
|
|
||||||
transaction.commit()
|
transaction.commit()
|
||||||
transaction.set_autocommit(True)
|
|
||||||
|
transaction.set_autocommit(True)
|
||||||
|
# last_pk might have increased because of influx of new pings:
|
||||||
|
last_pk = Ping.objects.order_by('-pk')[0].pk
|
||||||
|
|
||||||
self.stdout.write("Updating check.n_pings")
|
self.stdout.write("Updating check.n_pings")
|
||||||
for check_id, n_pings in counts.items():
|
for check_id, n_pings in counts.items():
|
||||||
|
Loading…
x
Reference in New Issue
Block a user